-
Notifications
You must be signed in to change notification settings - Fork 77
Implementing the chmod
support
#772
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
Changes from all commits
085a0dc
e403d8f
fffcf23
72bf01b
68e50f8
877af2e
14fefcb
a68438f
3de9383
60a3c42
e364ed6
c698586
0769ce3
c92704f
9e00b15
b3f089a
175ccaf
ee5f2c5
339582d
c95c2fe
ecf63d4
c1b4a3a
2fc47fb
b9bba29
df2a120
a16a439
4bc7526
68f1ab9
5980592
ace1f49
a294b64
94fae9e
112a261
dc85be0
dc5a0d8
e425842
e218917
1719151
662792a
651ebd5
ba943ff
0bb124d
75732f1
02225be
9390eb4
17a20aa
e54ce95
84cc303
04843a7
34e7ac4
650088b
cd4fb2b
ce4adee
e9b4c36
97d9220
e051c6e
a0e5da2
e6c0861
7fb0485
f477b32
0393837
55e7f8d
65689dc
0c79cbc
121137d
a060da7
fa65b09
38b1f77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ _opam | |
.ocamlformat | ||
.*.swp | ||
*.install | ||
.vscode |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -14,6 +14,7 @@ module Path = Eio.Path | |||
let () = Eio.Exn.Backend.show := false | ||||
|
||||
open Eio.Std | ||||
open Eio.Exn | ||||
|
||||
let ( / ) = Path.( / ) | ||||
|
||||
|
@@ -77,12 +78,13 @@ let chdir path = | |||
traceln "chdir %S" path; | ||||
Unix.chdir path | ||||
|
||||
let try_stat path = | ||||
let try_stat ?(info_type=`Kind) path = | ||||
let stat ~follow = | ||||
match Eio.Path.stat ~follow path with | ||||
| info -> Fmt.str "@[<h>%a@]" Eio.File.Stat.pp_kind info.kind | ||||
| exception Eio.Io (e, _) -> Fmt.str "@[<h>%a@]" Eio.Exn.pp_err e | ||||
in | ||||
match Eio.Path.stat ~follow path, info_type with | ||||
| info, `Perm -> Fmt.str "@[<h>%o@]" info.perm | ||||
| info, `Kind -> Fmt.str "@[<h>%a@]" Eio.File.Stat.pp_kind info.kind | ||||
| exception Eio.Io (e, _) -> Fmt.str "@[<h>%a@]" Eio.Exn.pp_err e | ||||
in | ||||
let a = stat ~follow:false in | ||||
let b = stat ~follow:true in | ||||
if a = b then | ||||
|
@@ -94,6 +96,11 @@ let try_symlink ~link_to path = | |||
match Path.symlink ~link_to path with | ||||
| s -> traceln "symlink %a -> %S" Path.pp path link_to | ||||
| exception ex -> traceln "@[<h>%a@]" Eio.Exn.pp ex | ||||
|
||||
let try_chmod path ~follow ~perm = | ||||
match Eio.Path.chmod ~follow path ~perm with | ||||
| () -> traceln "chmod %a to %o -> ok" Path.pp path perm | ||||
| exception ex -> traceln "@[<h>%a@]" Eio.Exn.pp ex | ||||
``` | ||||
|
||||
# Basic test cases | ||||
|
@@ -829,6 +836,7 @@ Unconfined: | |||
try_stat cwd; | ||||
try_stat (cwd / ".."); | ||||
try_stat (cwd / "stat_subdir2/.."); | ||||
|
||||
Path.symlink ~link_to:".." (cwd / "parent-symlink"); | ||||
try_stat (cwd / "parent-symlink"); | ||||
try_stat (cwd / "missing1" / "missing2"); | ||||
|
@@ -1011,3 +1019,36 @@ Exception: Failure "Simulated error". | |||
+"/" / "" = "/" | ||||
- : unit = () | ||||
``` | ||||
|
||||
```ocaml | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To run the test make sure you run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still holds true. |
||||
# run ~clear:["test-file"] @@ fun env -> | ||||
let cwd = Eio.Stdenv.cwd env in | ||||
Switch.run @@ fun sw -> | ||||
|
||||
let file_path = cwd / "test-file" in | ||||
Path.save ~create:(`Exclusive 0o644) file_path "test data"; | ||||
traceln "+create <cwd:test-file> with permissions 0o644 -> ok"; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea of these tests is that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we don't need this.
Suggested change
|
||||
|
||||
let initial_perm = (Path.stat ~follow:true file_path).perm in | ||||
traceln "+<cwd:test-file> initial permissions = %o" initial_perm; | ||||
assert (initial_perm = 0o644); | ||||
|
||||
try_chmod ~follow:true ~perm:0o400 file_path; | ||||
|
||||
try_stat ~info_type:`Perm file_path; | ||||
|
||||
try_chmod ~follow:true ~perm:0o600 file_path; | ||||
try_stat ~info_type:`Perm file_path; | ||||
|
||||
Eio.Path.unlink file_path; | ||||
traceln "+unlink <cwd:test-file> -> ok"; | ||||
() | ||||
++create <cwd:test-file> with permissions 0o644 -> ok | ||||
++<cwd:test-file> initial permissions = 644 | ||||
+chmod <cwd:test-file> to 400 -> ok | ||||
+<cwd:test-file> -> 400 | ||||
+chmod <cwd:test-file> to 600 -> ok | ||||
+<cwd:test-file> -> 600 | ||||
++unlink <cwd:test-file> -> ok | ||||
- : unit = () | ||||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like with the other functions that do not have an implementation, we should actually still create a stub in
eio_windows_stubs.c
that fails. See, for example, how symlink does it. This reduces the burden for someone to come along and do achmod
implementation for Windows.