aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-07-24 14:53:33 +0100
committergingerBill <bill@gingerbill.org>2024-07-24 14:53:33 +0100
commit07b1819dc8154e1786ebb8ce942e45200b0fc0d8 (patch)
treedcf94baf0c47ad5a821bdcc5c1b97bb09f047bd8
parent9d8953538bb28db656479ead989c14b9e3e08d6b (diff)
Improve `os2.read_directory`
-rw-r--r--core/os/os2/dir_windows.odin66
-rw-r--r--core/os/os2/stat.odin2
-rw-r--r--core/os/os2/stat_linux.odin2
-rw-r--r--core/os/os2/stat_windows.odin2
4 files changed, 30 insertions, 42 deletions
diff --git a/core/os/os2/dir_windows.odin b/core/os/os2/dir_windows.odin
index 99dbe3c17..c767bd3b9 100644
--- a/core/os/os2/dir_windows.odin
+++ b/core/os/os2/dir_windows.odin
@@ -15,30 +15,15 @@ find_data_to_file_info :: proc(base_path: string, d: ^win32.WIN32_FIND_DATAW, al
return
}
path := concatenate({base_path, `\`, win32_utf16_to_utf8(d.cFileName[:], temp_allocator()) or_else ""}, allocator) or_return
+
+
fi.fullpath = path
fi.name = basename(path)
fi.size = i64(d.nFileSizeHigh)<<32 + i64(d.nFileSizeLow)
- if d.dwFileAttributes & win32.FILE_ATTRIBUTE_READONLY != 0 {
- fi.mode |= 0o444
- } else {
- fi.mode |= 0o666
- }
-
- is_sym := false
- if d.dwFileAttributes & win32.FILE_ATTRIBUTE_REPARSE_Point == 0 {
- is_sym = false
- } else {
- is_sym = d.dwReserved0 == win32.IO_REPARSE_TAG_SYMLINK || d.dwReserved0 == win32.IO_REPARSE_TAG_MOUNT_POINT
- }
-
- if is_sym {
- fi.type = .Symlink
- } else if d.dwFileAttributes & win32.FILE_ATTRIBUTE_DIRECTORY != 0 {
- fi.type = .Directory
- fi.mode |= 0o111
- }
+ fi.type, fi.mode = _file_type_mode_from_file_attributes(d.dwFileAttributes, nil, d.dwReserved0)
+ // fi.inode = u128(u64(d.nFileIndexHigh)<<32 + u64(d.nFileIndexLow))
fi.creation_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftCreationTime))
fi.modification_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastWriteTime))
fi.access_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastAccessTime))
@@ -60,31 +45,33 @@ _read_directory_iterator :: proc(it: ^Read_Directory_Iterator) -> (fi: File_Info
if it.f == nil {
return
}
- if it.impl.no_more_files {
- return
- }
-
- err: Error
- fi, err = find_data_to_file_info(it.impl.path, &it.impl.find_data, file_allocator())
- if err != nil {
- return
- }
- if fi.name != "" {
+ for !it.impl.no_more_files {
+ err: Error
file_info_delete(it.impl.prev_fi, file_allocator())
- it.impl.prev_fi = fi
- ok = true
- index = it.impl.index
- it.impl.index += 1
- }
+ it.impl.prev_fi = {}
- if !win32.FindNextFileW(it.impl.find_handle, &it.impl.find_data) {
- e := _get_platform_error()
- if pe, _ := is_platform_error(e); pe == i32(win32.ERROR_NO_MORE_FILES) {
+ fi, err = find_data_to_file_info(it.impl.path, &it.impl.find_data, file_allocator())
+ if err != nil {
+ return
+ }
+ if fi.name != "" {
+ it.impl.prev_fi = fi
+ ok = true
+ index = it.impl.index
+ it.impl.index += 1
+ }
+
+ if !win32.FindNextFileW(it.impl.find_handle, &it.impl.find_data) {
+ e := _get_platform_error()
+ if pe, _ := is_platform_error(e); pe == i32(win32.ERROR_NO_MORE_FILES) {
+ it.impl.no_more_files = true
+ }
it.impl.no_more_files = true
}
- it.impl.no_more_files = true
- return
+ if ok {
+ return
+ }
}
return
}
@@ -94,6 +81,7 @@ _read_directory_iterator_create :: proc(f: ^File) -> (it: Read_Directory_Iterato
if f == nil {
return
}
+ it.f = f
impl := (^File_Impl)(f.impl)
if !is_directory(impl.name) {
diff --git a/core/os/os2/stat.odin b/core/os/os2/stat.odin
index a324e7189..5c063e771 100644
--- a/core/os/os2/stat.odin
+++ b/core/os/os2/stat.odin
@@ -11,7 +11,7 @@ File_Info :: struct {
fullpath: string,
name: string,
- inode: u64,
+ inode: u128, // might be zero if cannot be determined
size: i64,
mode: int,
type: File_Type,
diff --git a/core/os/os2/stat_linux.odin b/core/os/os2/stat_linux.odin
index eb31e2200..6ccac1be0 100644
--- a/core/os/os2/stat_linux.odin
+++ b/core/os/os2/stat_linux.odin
@@ -33,7 +33,7 @@ _fstat_internal :: proc(fd: linux.Fd, allocator: runtime.Allocator) -> (fi: File
fi = File_Info {
fullpath = _get_full_path(fd, allocator) or_return,
name = "",
- inode = u64(s.ino),
+ inode = u128(u64(s.ino)),
size = i64(s.size),
mode = mode,
type = type,
diff --git a/core/os/os2/stat_windows.odin b/core/os/os2/stat_windows.odin
index a3def0ea7..4d67ddb58 100644
--- a/core/os/os2/stat_windows.odin
+++ b/core/os/os2/stat_windows.odin
@@ -262,7 +262,7 @@ _file_info_from_get_file_information_by_handle :: proc(path: string, h: win32.HA
fi: File_Info
fi.fullpath = path
fi.name = basename(path)
- fi.inode = u64(d.nFileIndexHigh)<<32 + u64(d.nFileIndexLow)
+ fi.inode = u128(u64(d.nFileIndexHigh)<<32 + u64(d.nFileIndexLow))
fi.size = i64(d.nFileSizeHigh)<<32 + i64(d.nFileSizeLow)
type, mode := _file_type_mode_from_file_attributes(d.dwFileAttributes, nil, 0)
fi.type = type