Re: [AD] al_make_recursive_directory

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2010-10-23, Elias Pschernig <elias.pschernig@xxxxxxxxxx> wrote:
> On Sat, 2010-10-23 at 16:10 +0200, Elias Pschernig wrote:
> > On Sat, 2010-10-23 at 17:33 +1100, Peter Wang wrote:
> > > 
> > > There are numerous problems with the patch, which you will discover if
> > > you try it ;)
> > 
> > Yes, it was just pseudo-code, I discovered as soon as I compiled, right
> > after posting here... thought I had compiled before :P Anyway, was
> > trivial to fix.
> > 
> 
> Here's the real patch.

Actually this is the real real patch.

The reason I think the logic should be pushed into the fshook
implementations is that some file systems may not recognise '/' as
directory separators, and they may not *need* parent directories to be
created separately.

Peter


diff --git a/src/fshook.c b/src/fshook.c
index 8100dd1..84b9c0b 100644
--- a/src/fshook.c
+++ b/src/fshook.c
@@ -190,10 +190,38 @@ bool al_change_directory(const char *path)
 bool al_make_directory(const char *path)
 {
    const ALLEGRO_FS_INTERFACE *vt = al_get_fs_interface();
+   ALLEGRO_PATH *path1, *path2;
+   ALLEGRO_FS_ENTRY *fse;
+   const char *s;
+   int mode;
+   int i, n;
+   bool success = true;
+
    ASSERT(path);
    ASSERT(vt->fs_make_directory);
 
-   return vt->fs_make_directory(path);
+   path1 = al_create_path_for_directory(path);
+   path2 = al_create_path(NULL);
+   n = al_get_path_num_components(path1);
+   for (i = 0; i < n; i++) {
+      al_append_path_component(path2, al_get_path_component(path1, i));
+      s = al_path_cstr(path2, '/');
+      fse = al_create_fs_entry(s);
+      if (!fse) {
+         success = false;
+         break;
+      }
+      mode = al_get_fs_entry_mode(fse);
+      al_destroy_fs_entry(fse);
+      if (mode & ALLEGRO_FILEMODE_ISDIR)
+         continue;
+      success = vt->fs_make_directory(s);
+      if (!success)
+         break;
+   }
+   al_destroy_path(path1);
+   al_destroy_path(path2);
+   return success;
 }





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/