浏览代码

Improve `os2.read_directory`

gingerBill 1 年之前
父节点
当前提交
07b1819dc8
共有 4 个文件被更改,包括 30 次插入42 次删除
  1. 27 39
      core/os/os2/dir_windows.odin
  2. 1 1
      core/os/os2/stat.odin
  3. 1 1
      core/os/os2/stat_linux.odin
  4. 1 1
      core/os/os2/stat_windows.odin

+ 27 - 39
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
 		return
 	}
 	}
 	path := concatenate({base_path, `\`, win32_utf16_to_utf8(d.cFileName[:], temp_allocator()) or_else ""}, allocator) or_return
 	path := concatenate({base_path, `\`, win32_utf16_to_utf8(d.cFileName[:], temp_allocator()) or_else ""}, allocator) or_return
+
+
 	fi.fullpath = path
 	fi.fullpath = path
 	fi.name = basename(path)
 	fi.name = basename(path)
 	fi.size = i64(d.nFileSizeHigh)<<32 + i64(d.nFileSizeLow)
 	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.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.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))
 	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 {
 	if it.f == nil {
 		return
 		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())
 		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
 		}
 		}
-		it.impl.no_more_files = true
-		return
+		if ok {
+			return
+		}
 	}
 	}
 	return
 	return
 }
 }
@@ -94,6 +81,7 @@ _read_directory_iterator_create :: proc(f: ^File) -> (it: Read_Directory_Iterato
 	if f == nil {
 	if f == nil {
 		return
 		return
 	}
 	}
+	it.f = f
 	impl := (^File_Impl)(f.impl)
 	impl := (^File_Impl)(f.impl)
 
 
 	if !is_directory(impl.name) {
 	if !is_directory(impl.name) {

+ 1 - 1
core/os/os2/stat.odin

@@ -11,7 +11,7 @@ File_Info :: struct {
 	fullpath:          string,
 	fullpath:          string,
 	name:              string,
 	name:              string,
 
 
-	inode:             u64,
+	inode:             u128, // might be zero if cannot be determined
 	size:              i64,
 	size:              i64,
 	mode:              int,
 	mode:              int,
 	type:              File_Type,
 	type:              File_Type,

+ 1 - 1
core/os/os2/stat_linux.odin

@@ -33,7 +33,7 @@ _fstat_internal :: proc(fd: linux.Fd, allocator: runtime.Allocator) -> (fi: File
 	fi = File_Info {
 	fi = File_Info {
 		fullpath          = _get_full_path(fd, allocator) or_return,
 		fullpath          = _get_full_path(fd, allocator) or_return,
 		name              = "",
 		name              = "",
-		inode             = u64(s.ino),
+		inode             = u128(u64(s.ino)),
 		size              = i64(s.size),
 		size              = i64(s.size),
 		mode              = mode,
 		mode              = mode,
 		type              = type,
 		type              = type,

+ 1 - 1
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: File_Info
 	fi.fullpath = path
 	fi.fullpath = path
 	fi.name = basename(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)
 	fi.size  = i64(d.nFileSizeHigh)<<32  + i64(d.nFileSizeLow)
 	type, mode := _file_type_mode_from_file_attributes(d.dwFileAttributes, nil, 0)
 	type, mode := _file_type_mode_from_file_attributes(d.dwFileAttributes, nil, 0)
 	fi.type = type
 	fi.type = type