Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow checker to support reparsepoints in Windows #23

Merged
merged 4 commits into from
Jun 22, 2020
Merged

Allow checker to support reparsepoints in Windows #23

merged 4 commits into from
Jun 22, 2020

Conversation

fdncred
Copy link
Contributor

@fdncred fdncred commented Jun 18, 2020

No description provided.

@jonathanpallant
Copy link

On Linux, symlink_meta has metadata.is_file == False for symlinks, which means this crate won't find symlinks in /usr/bin for example.

Meta for "/usr/bin/xzcat":
Ok(
    Metadata {
        file_type: FileType(
            FileType {
                mode: 33261,
            },
        ),
        is_dir: false,
        is_file: true,
        permissions: Permissions(
            FilePermissions {
                mode: 33261,
            },
        ),
        modified: Ok(
            SystemTime {
                tv_sec: 1498667959,
                tv_nsec: 0,
            },
        ),
        accessed: Ok(
            SystemTime {
                tv_sec: 1591012305,
                tv_nsec: 0,
            },
        ),
        created: Ok(
            SystemTime {
                tv_sec: 1591012379,
                tv_nsec: 420000000,
            },
        ),
    },
)
Symlink Meta for "/usr/bin/xzcat":
Ok(
    Metadata {
        file_type: FileType(
            FileType {
                mode: 41471,
            },
        ),
        is_dir: false,
        is_file: false,
        permissions: Permissions(
            FilePermissions {
                mode: 41471,
            },
        ),
        modified: Ok(
            SystemTime {
                tv_sec: 1498667959,
                tv_nsec: 0,
            },
        ),
        accessed: Ok(
            SystemTime {
                tv_sec: 1592493357,
                tv_nsec: 230000000,
            },
        ),
        created: Ok(
            SystemTime {
                tv_sec: 1591012379,
                tv_nsec: 420000000,
            },
        ),
    },
)
Got Output { status: ExitStatus(ExitStatus(0)), stdout: "xz (XZ Utils) 5.2.2\nliblzma 5.2.2\n", stderr: "" }
Meta for "/usr/bin/xz":
Ok(
    Metadata {
        file_type: FileType(
            FileType {
                mode: 33261,
            },
        ),
        is_dir: false,
        is_file: true,
        permissions: Permissions(
            FilePermissions {
                mode: 33261,
            },
        ),
        modified: Ok(
            SystemTime {
                tv_sec: 1498667959,
                tv_nsec: 0,
            },
        ),
        accessed: Ok(
            SystemTime {
                tv_sec: 1592493388,
                tv_nsec: 410000000,
            },
        ),
        created: Ok(
            SystemTime {
                tv_sec: 1591012379,
                tv_nsec: 420000000,
            },
        ),
    },
)
Symlink Meta for "/usr/bin/xz":
Ok(
    Metadata {
        file_type: FileType(
            FileType {
                mode: 33261,
            },
        ),
        is_dir: false,
        is_file: true,
        permissions: Permissions(
            FilePermissions {
                mode: 33261,
            },
        ),
        modified: Ok(
            SystemTime {
                tv_sec: 1498667959,
                tv_nsec: 0,
            },
        ),
        accessed: Ok(
            SystemTime {
                tv_sec: 1592493388,
                tv_nsec: 410000000,
            },
        ),
        created: Ok(
            SystemTime {
                tv_sec: 1591012379,
                tv_nsec: 420000000,
            },
        ),
    },
)
Got Output { status: ExitStatus(ExitStatus(0)), stdout: "xz (XZ Utils) 5.2.2\nliblzma 5.2.2\n", stderr: "" }
❯ cargo run
   Compiling file_test v0.1.0 (C:\Users\jpallant\file_test)
    Finished dev [unoptimized + debuginfo] target(s) in 0.54s
     Running `target\debug\file_test.exe`
Meta for "C:\\Users\\jpallant\\AppData\\Local\\Microsoft\\WindowsApps\\winget.exe":
Err(
    Os {
        code: 1920,
        kind: Other,
        message: "The file cannot be accessed by the system.",
    },
)
Symlink Meta for "C:\\Users\\jpallant\\AppData\\Local\\Microsoft\\WindowsApps\\winget.exe":
Ok(
    Metadata {
        file_type: FileType(
            FileType {
                attributes: 1056,
                reparse_tag: 2147483675,
            },
        ),
        is_dir: false,
        is_file: true,
        permissions: Permissions(
            FilePermissions {
                attrs: 1056,
            },
        ),
        modified: Ok(
            SystemTime {
                intervals: 132354869816004065,
            },
        ),
        accessed: Ok(
            SystemTime {
                intervals: 132354869816004065,
            },
        ),
        created: Ok(
            SystemTime {
                intervals: 132354869816004065,
            },
        ),
    },
)
Got Output { status: ExitStatus(ExitStatus(0)), stdout: "v0.1.41331 Preview", stderr: "" }
Meta for "C:\\Python38\\Python.exe":
Ok(
    Metadata {
        file_type: FileType(
            FileType {
                attributes: 32,
                reparse_tag: 0,
            },
        ),
        is_dir: false,
        is_file: true,
        permissions: Permissions(
            FilePermissions {
                attrs: 32,
            },
        ),
        modified: Ok(
            SystemTime {
                intervals: 132338797780000000,
            },
        ),
        accessed: Ok(
            SystemTime {
                intervals: 132369667820021804,
            },
        ),
        created: Ok(
            SystemTime {
                intervals: 132338797780000000,
            },
        ),
    },
)
Symlink Meta for "C:\\Python38\\Python.exe":
Ok(
    Metadata {
        file_type: FileType(
            FileType {
                attributes: 32,
                reparse_tag: 0,
            },
        ),
        is_dir: false,
        is_file: true,
        permissions: Permissions(
            FilePermissions {
                attrs: 32,
            },
        ),
        modified: Ok(
            SystemTime {
                intervals: 132338797780000000,
            },
        ),
        accessed: Ok(
            SystemTime {
                intervals: 132369667820021804,
            },
        ),
        created: Ok(
            SystemTime {
                intervals: 132338797780000000,
            },
        ),
    },
)
Got Output { status: ExitStatus(ExitStatus(0)), stdout: "Python 3.8.3\r\n", stderr: "" }
use std::process::Command;

#[cfg(target_os="windows")]
static PATHS: [&str; 2] = [
    r"C:\Users\jpallant\AppData\Local\Microsoft\WindowsApps\winget.exe",
    r"C:\Python38\Python.exe",
];

#[cfg(target_os="linux")]
static PATHS: [&str; 2] = [
    r"/usr/bin/xzcat",
    r"/usr/bin/xz",
];

fn main() {
    for path in &PATHS {
        println!("Meta for {:?}:\n{:#?}", path, std::fs::metadata(path));
        println!(
            "Symlink Meta for {:?}:\n{:#?}",
            path,
            std::fs::symlink_metadata(path)
        );

        let output = Command::new(path)
            .arg("--version")
            .output()
            .expect("Failed to execute command");

        println!("Got {:?}", output);
    }
}

@harryfei
Copy link
Owner

Does that mean we should use different ExistedChecker implementations for Linux and Windows?

@jonathanpallant
Copy link

Yeah I can't see a way around that at the moment. Windows' concept of symlinks is quite different to POSIX OSes like Linux and macOS.

@fdncred
Copy link
Contributor Author

fdncred commented Jun 18, 2020

ok, @jonathanpallant. Thanks for testing. @harryfei , how does this look?

impl Checker for ExistedChecker {
    #[cfg(target_os="windows")]
    fn is_valid(&self, path: &Path) -> bool {
        fs::symlink_metadata(path)
            .map(|metadata| metadata.is_file())
            .unwrap_or(false)
    }

    #[cfg(not(target_os="windows"))]
    fn is_valid(&self, path: &Path) -> bool {
        fs::metadata(path)
            .map(|metadata| metadata.is_file())
            .unwrap_or(false)
    }
}

@fdncred
Copy link
Contributor Author

fdncred commented Jun 19, 2020

@harryfei Any idea what this CI error means?

@fdncred
Copy link
Contributor Author

fdncred commented Jun 20, 2020

CI is glitchy here. Not sure what needs to happen to get this merged. @harryfei can you help please?

@harryfei harryfei closed this Jun 21, 2020
@harryfei harryfei reopened this Jun 21, 2020
@harryfei
Copy link
Owner

So odd. I can merge it without passing all the CI jobs.
I think you will delete the Tweak to get CI to run again. commit.

@fdncred
Copy link
Contributor Author

fdncred commented Jun 21, 2020

@harryfei Deleted the Tweak commit. Looks like all checks finally passed. I have no idea what was causing that glitch.

src/checker.rs Outdated
@@ -23,7 +23,7 @@ impl Checker for ExecutableChecker {
.and_then(|c| Ok(unsafe { libc::access(c.as_ptr(), libc::X_OK) == 0 }))
.unwrap_or(false)
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected spaces.

Copy link
Contributor Author

@fdncred fdncred Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you saying you don't want these spaces or i should remove the line entirely? I removed the spaces.

@fdncred fdncred requested a review from harryfei June 22, 2020 12:51
@harryfei harryfei merged commit 209804c into harryfei:master Jun 22, 2020
@fdncred fdncred deleted the patch-1 branch June 22, 2020 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants