@@ -52,13 +52,13 @@ if ffi.arch ~= "Windows" then
5252 uint32_t st_uid;
5353 uint32_t st_gid;
5454 uint32_t st_rdev;
55- time_t st_atime;
55+ size_t st_atime;
5656 long st_atime_nsec;
57- time_t st_mtime;
57+ size_t st_mtime;
5858 long st_mtime_nsec;
59- time_t st_ctime;
59+ size_t st_ctime;
6060 long st_ctime_nsec;
61- time_t st_btime;
61+ size_t st_btime;
6262 long st_btime_nsec;
6363 int64_t st_size;
6464 int64_t st_blocks;
@@ -672,64 +672,63 @@ function fs.iterate(dir, pattern)
672672end
673673
674674function fs .get_parent_directory (path )
675- -- Normalize path separators to forward slash
676- path = path :gsub (" \\ " , " /" )
677-
678- -- Remove trailing slash if present
679- if path :sub (- 1 ) == " /" and path ~= " /" then
680- path = path :sub (1 , - 2 )
681- end
682-
683- -- Extract parent directory
684- local parent = path :match (" (.+)/[^/]+$" )
685-
686- -- Handle special cases
687- if not parent then
688- if path == " /" then
689- return nil -- Root has no parent
690- else
691- return " ." -- Current directory is parent
692- end
693- end
694-
695- -- Return the parent directory
696- return parent
675+ -- Normalize path separators to forward slash
676+ path = path :gsub (" \\ " , " /" )
677+
678+ -- Remove trailing slash if present
679+ if path :sub (- 1 ) == " /" and path ~= " /" then
680+ path = path :sub (1 , - 2 )
681+ end
682+
683+ -- Extract parent directory
684+ local parent = path :match (" (.+)/[^/]+$" )
685+
686+ -- Handle special cases
687+ if not parent then
688+ if path == " /" then
689+ return nil -- Root has no parent
690+ else
691+ return " ." -- Current directory is parent
692+ end
693+ end
694+
695+ -- Return the parent directory
696+ return parent
697697end
698698
699699function fs .create_directory_recursive (path )
700- -- Handle empty or root path
701- if path == " " or path == " /" then return true end
702-
703- -- Normalize path separators to forward slash
704- path = path :gsub (" \\ " , " /" )
705-
706- -- Remove trailing slash if present
707- if path :sub (- 1 ) == " /" then
708- path = path :sub (1 , - 2 )
709- end
710-
711- -- Check if directory already exists
712- if fs .exists (path ) then
713- if fs .is_directory (path ) then
714- return true -- Already exists as directory
715- else
716- return nil , " Path exists but is not a directory" -- Path exists as a file
717- end
718- end
719-
720- -- Get parent directory
721- local parent = path :match (" (.+)/[^/]+$" ) or " "
722-
723- -- If parent directory doesn't exist, create it first
724- if parent ~= " " and not fs .exists (parent ) then
725- local ok , err = fs .create_directory_recursive (parent )
726- if not ok then
727- return nil , " Failed to create parent directory: " .. (err or " unknown error" )
728- end
729- end
730-
731- -- Create the directory
732- return fs .create_directory (path )
700+ -- Handle empty or root path
701+ if path == " " or path == " /" then return true end
702+
703+ -- Normalize path separators to forward slash
704+ path = path :gsub (" \\ " , " /" )
705+
706+ -- Remove trailing slash if present
707+ if path :sub (- 1 ) == " /" then path = path :sub (1 , - 2 ) end
708+
709+ -- Check if directory already exists
710+ if fs .exists (path ) then
711+ if fs .is_directory (path ) then
712+ return true -- Already exists as directory
713+ else
714+ return nil , " Path exists but is not a directory" -- Path exists as a file
715+ end
716+ end
717+
718+ -- Get parent directory
719+ local parent = path :match (" (.+)/[^/]+$" ) or " "
720+
721+ -- If parent directory doesn't exist, create it first
722+ if parent ~= " " and not fs .exists (parent ) then
723+ local ok , err = fs .create_directory_recursive (parent )
724+
725+ if not ok then
726+ return nil , " Failed to create parent directory: " .. (err or " unknown error" )
727+ end
728+ end
729+
730+ -- Create the directory
731+ return fs .create_directory (path )
733732end
734733
735734return fs
0 commit comments