8000 Implement windows platform target \`is_junction\` with junction library · RustPython/RustPython@c66dbcb · GitHub
[go: up one dir, main page]

Skip to content

Commit c66dbcb

Browse files
committed
Implement windows platform target \is_junction\ with junction library
1 parent 1cd4e45 commit c66dbcb

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vm/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ schannel = { workspace = true }
106106
widestring = { workspace = true }
107107
winreg = "0.10.1"
108108

109+
[target.'cfg(windows)'.dependencies.junction]
110+
version = "1.0.0"
111+
109112
[target.'cfg(windows)'.dependencies.windows]
110113
version = "0.52.0"
111114
features = [

vm/src/stdlib/os.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,37 @@ pub(super) mod _os {
748748
#[cfg(windows)]
749749
#[pymethod]
750750
fn is_junction(&self, _vm: &VirtualMachine) -> PyResult<bool> {
751-
fs::metadata(&path).map_or(false, |meta| meta.file_type().is_dir())
752-
&& fs::symlink_metadata(&path).map_or(false, |meta| meta.file_type().is_symlink())
751+
Ok(junction::exists(self.pathval.clone()).expect("Failed to check it is junction."))
752+
// unsafe {
753+
// use std::os::{
754+
// windows::fs::{MetadataExt, IO_REPARSE_TAG_MOUNT_POINT},
755+
// raw::c_ulong,
756+
// };
757+
// use std::mem;
758+
// use window_sys::Win32::Storage::FileSystem::{FILE_ATTRIBUTE_TAG_INFO, FileAttributeTagInfo, GetFileInformationByHandleEx, FILE_ATTRIBUTE_REPARSE_POINT, GetFileInformationByHandle, BY_HANDLE_FILE_INFORMATION};
759+
//
760+
// let f = OpenOptions::new()
761+
// .read(true)
762+
// .custom_flags(windows_sys::Win32::Storage::FileSystem::FILE_FLAG_BACKUP_SEMANTICS)
763+
// .open(path)
764+
// .map_err(|err| err.into_pyexception(vm))?;
765+
//
766+
// let mut info: BY_HANDLE_FILE_INFORMATION = mem::zeroed();
767+
// GetFileInformationByHandle(f.as_raw_handle(), &mut info);
768+
// let mut reparse_tag = 0;
769+
// if info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT != 0 {
770+
// let mut attr_tag: FILE_ATTRIBUTE_TAG_INFO = mem::zeroed();
771+
// GetFileInformationByHandleEx(
772+
// self.handle.as_raw_handle(),
773+
// FileAttributeTagInfo,
774+
// ptr::addr_of_mut!(attr_tag).cast(),
775+
// mem::size_of::<FILE_ATTRIBUTE_TAG_INFO>().try_into().unwrap(),
776+
// );
777+
// if attr_tag.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT != 0 {
778+
// reparse_tag = attr_tag.ReparseTag;
779+
// }
780+
// }
781+
// }
753782
}
754783

755784
#[pymethod(magic)]

0 commit comments

Comments
 (0)
0