File: accomodate-more-environments-in-testsuite.patch

package info (click to toggle)
rust-faccess 0.2.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 156 kB
  • sloc: makefile: 2
file content (62 lines) | stat: -rw-r--r-- 1,992 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Index: faccess/src/lib.rs
===================================================================
--- faccess.orig/src/lib.rs
+++ faccess/src/lib.rs
@@ -510,10 +510,26 @@ impl PathExt for Path {
 
 #[test]
 fn amazing_test_suite() {
-    let cargotoml = Path::new("Cargo.toml");
+    let mut cargotoml = Path::new("Cargo.toml");
 
     assert!(cargotoml.access(AccessMode::EXISTS).is_ok());
     assert!(cargotoml.access(AccessMode::READ).is_ok());
+
+    let tempdir; //declared outside the if so it isn't dropped prematurely
+    let cargotomlnew; //declared outside the if so it isn't dropped prematurely
+    let writable = cargotoml
+        .access(AccessMode::READ | AccessMode::WRITE)
+        .is_ok();
+    if !writable {
+        use tempfile::TempDir;
+        use std::fs::copy;
+        tempdir = TempDir::new().unwrap();
+        cargotomlnew = tempdir.path().join("cargo.toml");
+        copy(cargotoml,&cargotomlnew);
+        cargotoml = &cargotomlnew;
+    }
+
+
     assert!(cargotoml
         .access(AccessMode::READ | AccessMode::WRITE)
         .is_ok());
@@ -530,11 +546,13 @@ fn amazing_test_suite() {
 
         let sh = Path::new("/bin/sh");
         assert!(sh.readable());
-        assert!(!sh.writable());
+        use libc::geteuid;
+        let is_root = unsafe { geteuid() } == 0;
+        assert!(sh.writable() == is_root);
         assert!(sh.executable());
 
         assert!(sh.access(AccessMode::READ | AccessMode::EXECUTE).is_ok());
-        assert!(sh.access(AccessMode::READ | AccessMode::WRITE).is_err());
+        assert!(sh.access(AccessMode::READ | AccessMode::WRITE).is_ok() == is_root);
     }
 
     #[cfg(windows)]
Index: faccess/Cargo.toml
===================================================================
--- faccess.orig/Cargo.toml
+++ faccess/Cargo.toml
@@ -33,6 +33,9 @@ targets = []
 [dependencies.bitflags]
 version = "1.2.1"
 
+[dev-dependencies.tempfile]
+version = "3"
+
 [target."cfg(unix)".dependencies.libc]
 version = "~0.2.68"