-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_systems.clj
91 lines (70 loc) · 3.22 KB
/
file_systems.clj
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
(ns pathological.file-systems
(:import
[java.nio.file FileSystem FileSystems]))
(defn ^FileSystem default-file-system
"Returns the default file system for the JVM.
See [the Java documentation](https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystems.html#getDefault%28%29)
for more details."
[]
(FileSystems/getDefault))
(def ^{:dynamic true :tag FileSystem} *file-system*
"The file system to use in various calls where no file system is provided,
e.g., [[pathological.paths/path]],
[[pathological.principals/->user-principal]] and
[[pathological.principals/->group-principal]]
By default, the [[default-file-system]] is used. However this var is dynamic
and can be altered / rebound to any file system instance."
(default-file-system))
(defn open?
"Returns true if the file system is open, false otherwise.
See [the Java documentation](https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#isOpen%28%29)
for more details."
[^FileSystem file-system]
(.isOpen file-system))
(defn read-only?
"Returns true if the file system is read only, false otherwise.
See [the Java documentation](https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#isReadOnly%28%29)
for more details."
[^FileSystem file-system]
(.isReadOnly file-system))
(defn close
"Closes the file system.
See [the Java documentation](https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#close%28%29)
for more details."
[^FileSystem file-system]
(.close file-system))
(defn provider
"Returns the provider for the file system.
See [the Java documentation](https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#provider%28%29)
for more details."
[^FileSystem file-system]
(.provider file-system))
(defn file-stores
"Returns the collection of file stores associated with the file system.
The file stores are returned as materialised records as specified in
[[pathological.file-stores/->file-store]].
See [the Java documentation](https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#getFileStores%28%29)
for more details."
[^FileSystem file-system]
(map (requiring-resolve 'pathological.file-stores/->file-store)
(.getFileStores file-system)))
(defn root-directories
"Returns a set of paths representing the root directories of the file
system.
See [the Java documentation](https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#getRootDirectories%28%29)
for more details."
[^FileSystem file-system]
(set (.getRootDirectories file-system)))
(defn separator
"Returns the name separator used by the file system.
See [the Java documentation](https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#getSeparator%28%29)
for more details."
[^FileSystem file-system]
(.getSeparator file-system))
(defn supported-file-attribute-views
"Returns a set of keywords representing the supported file attribute views
for the file system.
See [the Java documentation](https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#supportedFileAttributeViews%28%29)
for more details."
[^FileSystem file-system]
(set (map keyword (.supportedFileAttributeViews file-system))))