diff --git a/core/os/dir_linux.odin b/core/os/dir_linux.odin index dc6bce390..851bd1635 100644 --- a/core/os/dir_linux.odin +++ b/core/os/dir_linux.odin @@ -28,7 +28,7 @@ read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []F size = 100; } - dfi := make([dynamic]File_Info, 0, size); + dfi := make([dynamic]File_Info, 0, size, allocator); for { entry: Dirent; @@ -36,7 +36,7 @@ read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []F entry, err, end_of_stream = _readdir(dirp); if err != ERROR_NONE { for fi_ in dfi { - file_info_delete(fi_); + file_info_delete(fi_, allocator); } delete(dfi); return; @@ -45,15 +45,19 @@ read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []F } fi_: File_Info; - filename := cast(string)(transmute(cstring)mem.Raw_Cstring{ data = &entry.name[0] }); - fullpath := strings.join( []string{ dirpath, filename }, "/" ); - defer delete(fullpath); - fi_, err = stat(fullpath); + if filename == "." || filename == ".." { + continue; + } + + fullpath := strings.join( []string{ dirpath, filename }, "/", context.temp_allocator); + defer delete(fullpath, context.temp_allocator); + + fi_, err = stat(fullpath, allocator); if err != ERROR_NONE { for fi__ in dfi { - file_info_delete(fi__); + file_info_delete(fi__, allocator); } delete(dfi); return; diff --git a/core/os/stat_linux.odin b/core/os/stat_linux.odin index 61673aa9e..31ac8f6f1 100644 --- a/core/os/stat_linux.odin +++ b/core/os/stat_linux.odin @@ -63,14 +63,17 @@ _fill_file_info_from_stat :: proc(fi: ^File_Info, s: Stat) { fi.mode = cast(File_Mode)s.mode; fi.is_dir = S_ISDIR(s.mode); - // NOTE(laleksic, 2021-01-21): Not really creation time, but closest we can get (maybe better to leave it 0?) - fi.creation_time = _make_time_from_unix_file_time(s.status_change); - + // NOTE(laleksic, 2021-01-21): Not really creation time, but closest we can get (maybe better to leave it 0?) + fi.creation_time = _make_time_from_unix_file_time(s.status_change); + fi.modification_time = _make_time_from_unix_file_time(s.modified); fi.access_time = _make_time_from_unix_file_time(s.last_access); } lstat :: proc(name: string, allocator := context.allocator) -> (fi: File_Info, err: Errno) { + + context.allocator = allocator; + s: Stat; s, err = _lstat(name); if err != ERROR_NONE { @@ -80,12 +83,15 @@ lstat :: proc(name: string, allocator := context.allocator) -> (fi: File_Info, e fi.fullpath, err = absolute_path_from_relative(name); if err != ERROR_NONE { return; - } + } fi.name = path.base(fi.fullpath); return fi, ERROR_NONE; } stat :: proc(name: string, allocator := context.allocator) -> (fi: File_Info, err: Errno) { + + context.allocator = allocator; + s: Stat; s, err = _stat(name); if err != ERROR_NONE { @@ -101,6 +107,9 @@ stat :: proc(name: string, allocator := context.allocator) -> (fi: File_Info, er } fstat :: proc(fd: Handle, allocator := context.allocator) -> (fi: File_Info, err: Errno) { + + context.allocator = allocator; + s: Stat; s, err = _fstat(fd); if err != ERROR_NONE { @@ -110,7 +119,7 @@ fstat :: proc(fd: Handle, allocator := context.allocator) -> (fi: File_Info, err fi.fullpath, err = absolute_path_from_handle(fd); if err != ERROR_NONE { return; - } + } fi.name = path.base(fi.fullpath); return fi, ERROR_NONE; }