@@ -23,6 +23,23 @@ undef on failure and store the error message in the `fail` attribute.
23
23
- SUCCESS: nothing changed (boolean true)
24
24
- CHANGED: something changed (boolean true).
25
25
26
+ #### Functions
27
+
28
+ - mkcafpath
29
+
30
+ Returns an instance of [ Object] ( ../CAF/Object.md ) and ` CAF::Path ` .
31
+ This instance is a simple way to use ` CAF::Path ` when
32
+ subclassing is not possible. Allowed options are
33
+ ` <log = ` $logger>> and ` <NoAction = ` $noaction>>.
34
+
35
+ This function is not exported, to be used as e.g.
36
+ use CAF::Path;
37
+ ...
38
+ my $cafpath = CAF::Path::mkcafpath(log => $logger);
39
+ if(! defined($cafpath->directory($name)) {
40
+ $logger->error("Failed to make directory $name: $cafpath->{fail}");
41
+ };
42
+
26
43
#### Methods
27
44
28
45
- \_ get\_ noaction
@@ -53,8 +70,10 @@ undef on failure and store the error message in the `fail` attribute.
53
70
54
71
Run function reference ` funcref ` with arrayref ` argsref ` and hashref ` optsref ` .
55
72
56
- Return and set fail attribute with ` failmsg ` on die, verbose ` msg ` on success
57
- (resp. $@ and stringified result are appended).
73
+ Return and set fail attribute with ` failmsg ` on die or an error (` undef ` returned
74
+ by ` funcref ` ), or print (at verbose level) ` msg ` on success (respectively $@ and
75
+ stringified result are appended). Note that ` _safe_eval ` doesn't work with functions
76
+ that don't return a defined value when they succeed.
58
77
59
78
Resets previous exceptions and/or fail attribute
60
79
@@ -80,7 +99,7 @@ undef on failure and store the error message in the `fail` attribute.
80
99
wrapped in a method to allow unittesting.
81
100
82
101
If ` directory ` is a symlink, the symlink target
83
- is tested. If the symlink is broken (no target),
102
+ is tested. If the symlink is broken (no target),
84
103
` directory_exists ` returns false.
85
104
86
105
- file\_ exists
@@ -91,7 +110,7 @@ undef on failure and store the error message in the `fail` attribute.
91
110
wrapped in a method to allow unittesting.
92
111
93
112
If ` filename ` is a symlink, the symlink target
94
- is tested. If the symlink is broken (no target),
113
+ is tested. If the symlink is broken (no target),
95
114
` file_exists ` returns false.
96
115
97
116
- any\_ exists
@@ -104,6 +123,13 @@ undef on failure and store the error message in the `fail` attribute.
104
123
A broken symlink (symlink whose target doesn't
105
124
exist) exists: ` any_exists ` returns true.
106
125
126
+ - is\_ symlink
127
+
128
+ Test if ` path ` is a symlink.
129
+
130
+ Returns true as long as ` path ` is a symlink, including when the
131
+ symlink target doesn't exist.
132
+
107
133
- cleanup
108
134
109
135
cleanup removes ` dest ` with backup support.
@@ -114,7 +140,7 @@ undef on failure and store the error message in the `fail` attribute.
114
140
Returns CHANGED is something was cleaned-up, SUCCESS if nothing was done
115
141
and undef on failure (and sets the fail attribute).
116
142
117
- The & lt ; backup> is a suffix for ` dest ` .
143
+ The < backup > is a suffix for ` dest ` .
118
144
119
145
If backup is undefined, use ` backup ` attribute.
120
146
(Pass an empty string to disable backup with ` backup ` attribute defined)
@@ -159,6 +185,76 @@ undef on failure and store the error message in the `fail` attribute.
159
185
160
186
- keeps\_ state: boolean passed to ` _get_noaction ` .
161
187
188
+ - \_ make\_ link
189
+
190
+ This method is mainly a wrapper over ` LC::Check::link `
191
+ returning the standard ` CAF::Path ` return values. Every option
192
+ supported by ` LC::Check::link ` is supported. ` NoAction `
193
+ flag is handled by ` LC::Check::link ` and ` keeps_state ` option
194
+ is honored (overrides ` NoAction ` if true). One important
195
+ difference is the order of the arguments: ` CAF::Path:_make_link `
196
+ and the methods based on it are following the Perl ` symlink `
197
+ (and ` ln ` command) argument order.
198
+
199
+ This is an internal method, not supposed to be called directly.
200
+ Either call [ symlink] ( ../components/symlink.md ) or ` hardlink ` public methods instead.
201
+
202
+ - hardlink
203
+
204
+ Create a hardlink ` link_path ` whose target is ` target ` .
205
+
206
+ On failure, returns undef and sets the fail attribute.
207
+ If ` link_path ` exists and is a file, it is updated.
208
+ ` target ` must exist (` check ` flag available in symlink()
209
+ is ignored for hardlinks) and it must reside in the same
210
+ filesystem as ` link_path ` . If ` target_path ` is a
211
+ relative path, it is interpreted from the current directory.
212
+ ` link_name ` parent directory is created if it doesn't exist.
213
+
214
+ Returns SUCCESS on sucess if the hardlink already existed
215
+ with the same target, CHANGED if the hardlink was created
216
+ or updated, undef otherwise.
217
+
218
+ This method relies on ` _make_link ` method to do the real work,
219
+ after enforcing the option saying that it is a hardlink.
220
+
221
+ - symlink
222
+
223
+ Create a symlink ` link_path ` whose target is ` target ` .
224
+
225
+ Returns undef and sets the fail attribute if ` link_path `
226
+ already exists and is not a symlink, except if this is a file
227
+ and option ` force ` is defined and true. If ` link_path ` exists
228
+ and is a symlink, it is updated. By default, the target is not
229
+ required to exist. If you want to ensure that it exists,
230
+ define option ` check ` to true. Both ` link_path ` and ` target `
231
+ can be relative paths: ` link_path ` is interpreted as relatif
232
+ to the current directory and ` target ` is kept relative.
233
+ ` link_path ` parent directory is created if it doesn't exist.
234
+
235
+ Returns SUCCESS on sucess if the symlink already existed
236
+ with the same target, CHANGED if the symlink was created
237
+ or updated, undef otherwise.
238
+
239
+ This method relies on ` _make_link ` method to do the real work,
240
+ after enforcing the option saying that it is a symlink.
241
+
242
+ - has\_ hardlinks
243
+
244
+ Method that returns the number of hardlinks for ` file ` . The number of
245
+ hardlinks is the number of entries referring to the inodes minus 1. If
246
+ ` file ` has no hardlink, the return value is 0. If ` file ` is not a file,
247
+ the return value is ` undef ` .
248
+
249
+ - is\_ hardlink
250
+
251
+ This method returns SUCCESS if ` path1 ` and ` path2 ` refer to the same file (inode).
252
+ It returns 0 if ` path1 ` and ` path2 ` both exist but are different files or are the same path
253
+ and ` undef ` if one of the paths doesn't exist or is not a file.
254
+
255
+ Note: the result returned will be identical whatever is the order of ` path1 ` and ` path2 `
256
+ arguments.
257
+
162
258
- status
163
259
164
260
Set the path stat options: ` owner ` , ` group ` , ` mode ` and/or ` mtime ` .
@@ -182,7 +278,7 @@ undef on failure and store the error message in the `fail` attribute.
182
278
does not exist to start with, success is immediately returned,
183
279
and no backup of ` dest ` is created).
184
280
185
- The & lt ; backup> is a suffix for the cleanup of ` dest `
281
+ The < backup > is a suffix for the cleanup of ` dest `
186
282
(and passed to ` cleanup ` method).
187
283
188
284
(The basedir of ` dest ` is created using ` directory ` method.)
0 commit comments