| 1 |
/* |
| 2 |
** NSFileManager+Extensions.m |
| 3 |
** |
| 4 |
** Copyright (c) 2004-2007 Ludovic Marcotte |
| 5 |
** |
| 6 |
** Author: Ludovic Marcotte <[email protected]> |
| 7 |
** |
| 8 |
** This library is free software; you can redistribute it and/or |
| 9 |
** modify it under the terms of the GNU Lesser General Public |
| 10 |
** License as published by the Free Software Foundation; either |
| 11 |
** version 2.1 of the License, or (at your option) any later version. |
| 12 |
** |
| 13 |
** This library is distributed in the hope that it will be useful, |
| 14 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
** Lesser General Public License for more details. |
| 17 |
** |
| 18 |
** You should have received a copy of the GNU General Public License |
| 19 |
** along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#import <Pantomime/NSFileManager+Extensions.h> |
| 23 |
|
| 24 |
#import <Foundation/NSValue.h> |
| 25 |
|
| 26 |
// |
| 27 |
// |
| 28 |
// |
| 29 |
@implementation NSFileManager (PantomimeFileManagerExtensions) |
| 30 |
|
| 31 |
- (void) enforceMode: (unsigned long) theMode |
| 32 |
atPath: (NSString *) thePath |
| 33 |
|
| 34 |
{ |
| 35 |
NSMutableDictionary *currentFileAttributes; |
| 36 |
|
| 37 |
unsigned long current_attributes, desired_attributes; |
| 38 |
|
| 39 |
|
| 40 |
currentFileAttributes = [[NSMutableDictionary alloc] initWithDictionary: [self fileAttributesAtPath: thePath |
| 41 |
traverseLink: YES]]; |
| 42 |
|
| 43 |
current_attributes = [currentFileAttributes filePosixPermissions]; |
| 44 |
desired_attributes = theMode; |
| 45 |
|
| 46 |
if (current_attributes != desired_attributes) |
| 47 |
{ |
| 48 |
[currentFileAttributes setObject: [NSNumber numberWithUnsignedLong: desired_attributes] |
| 49 |
forKey: NSFilePosixPermissions]; |
| 50 |
|
| 51 |
[self changeFileAttributes: currentFileAttributes atPath: thePath]; |
| 52 |
} |
| 53 |
|
| 54 |
[currentFileAttributes release]; |
| 55 |
} |
| 56 |
|
| 57 |
@end |