-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSSYSuperFileManager.h
145 lines (123 loc) · 5.67 KB
/
SSYSuperFileManager.h
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#import <Cocoa/Cocoa.h>
/*!
@brief A more powerful replacement for some NSFileManager functions,
which can present an authentication dialog and perform some actions with
elevated permissions if necessary.
@details THIS CLASS IS NOT RECOMMENDED FOR NEW DESIGNS. See below.
This class requires CPHTaskMaster, which in turn requires
Mac OS X 10.6, to do anything useful. If the deployment target
(MAC_OS_X_VERSION_MIN_REQUIRED) is Mac OS X 10.5 or less,
methods in this class will return an error if called upon to do
anything that NSFileManager can't do. The idea is that you
can still use it in targets compiled with low deployment
targets.
However, CPHTaskManager has been giving me trouble in recent verions
of OS X, in particular I've been getting CPHTaskmasterBlessingFailed errors
when attempting to install the helper tool. Because I deemed the feature
using this class to be not worth fixing, I've stopped using it. If you want
to use this class, you'll need to study Apple's latest security model and
the current requirements of SMJobBless. I also remember seeing that there is
now a successor to BetterAuthorizationSample, but can't find it now. I think
that Apple needs to update TN2095. -- JK, 2014 09 01
*/
@interface SSYSuperFileManager : NSFileManager {
}
/*!
@brief Re-declaration to avoid compiler warnings when instantiating
this class since superclass declaration of this method is declared
to return the superclass, not id.
*/
+ (SSYSuperFileManager*)defaultManager ;
/*!
@brief Sets given permissions of a filesystem item at a given path,
presenting an authentication dialog if necessary, and returning records
of any permissions that were successfully changed
@param permission The value of the BSD permissions to be set,
typically a number such as octal 40777. Remember that the compiler
interprets a literal integer with a leading zero to be an octal number;
i.e. 040777 = 0x41FF = decimal 16895.
@param path The path for which permissions should be changed
@param changedPermissions If permissions were successfully changed,
the given path will be added as a key to this dictionary, with a value
equal to an NSNumber whose unsigned short value is the original permissions
of the parent directory before they were changed.
@param error_p Pointer to an NSError which, if permissions could not be
changed , will point to an NSError instance explaining why
permissions could not be changed. Otherwise, this pointer will be
untouched.
@result YES if the permissions were successfully changed.
*/
- (BOOL)setPermissions:(mode_t)permission
path:(NSString*)path
changedPermissions:(NSMutableDictionary*)changedPermissions
error_p:(NSError**)error_p ;
/*!
@brief Sets permissions of one or more filesystem items, specified
in a dictionary, presenting an authentication dialog if necessary.
@details
@param permissions A dictionary of filesystem paths (keys) and
their desired permissions (values). The keys should be NSString
objects, and the values NSNumber objects whose unsigned short value
represents the desired permissions. Note that the BSD permissions
type mode_t is unsigned short.
@param error_p Pointer to an NSError*, or nil. If non-nil, and
if an error occurred, will, upon exit, point to an NSError describing
the problem.
@result YES if the operation was successful, otherwise NO
*/
- (BOOL)setBulkPermissions:(NSDictionary*)permissions
error_p:(NSError**)error_p ;
/*!
@brief Determines whether or not a file exists at a given path,
asking for administrator authentication if necessary to access it.
@details Improved version of -fileExistsAtPath:isDirectory.
While traversing the path, if unable to enter because of permissions,
asks user for authentication and momentarily sets permissions to
040777. Restores all permissions to old values before
returning.
@param isDirectory_p Upon return, contains YES if path is a
directory or if the final path element is a symbolic link that
points to a directory, otherwise contains NO. If path
doesn’t exist, the return value is undefined. Pass NULL
if you do not need this information.
@param didElevate_p Pointer which will, if not nil, upon return,
point to a BOOL indicating whether or not it was necessary to
ask the user for elevated permissions to perform the operation.
Pass NULL if you do not need this information.
@param error_p Pointer which will, upon return, if an error
occured and said pointer is not NULL, point to an NSError
describing said error.
@result YES if the path could be probed and was found to exist,
otherwise NO.
*/
- (BOOL)fileExistsAtPath:(NSString*)path
isDirectory_p:(BOOL*)isDirectory
didElevate_p:(BOOL*)didElevate_p
error_p:(NSError**)error_p ;
/*!
@brief Invokes -fileExistsAtPath:isDirectory_p:error_p
with isDirectory_p set to NULL.
*/
- (BOOL)fileExistsAtPath:(NSString*)path
didElevate_p:(BOOL*)didElevate_p
error_p:(NSError**)error_p ;
- (BOOL)canExecutePath:(NSString*)fullPath
groupID:(uid_t)groupID
userID:(uid_t) userID ;
/*!
@brief
@details
@param path
@param error_p A pointer to an NSError instance, or nil if
you're not interested in the error. If you pass a pointer, and
the requested result cannot be returned, will point to an
NSError explaning the problem upon output.
For efficiency in case you expect that a path may not exist
and pass error_p = NULL, we don't create a local error. If
you pass a non-NULL error_p, it should point to nil (i.e.
there should be no "pre-existing" error).
@result
*/
- (NSDate*)modificationDateForPath:(NSString*)path
error_p:(NSError**)error_p ;
@end