1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "updaterfileutils_osx.h"
8 #include <Cocoa/Cocoa.h>
10 bool IsRecursivelyWritable(const char* aPath) {
11 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
13 NSString* rootPath = [NSString stringWithUTF8String:aPath];
14 NSFileManager* fileManager = [NSFileManager defaultManager];
16 NSArray* subPaths = [fileManager subpathsOfDirectoryAtPath:rootPath error:&error];
17 NSMutableArray* paths = [NSMutableArray arrayWithCapacity:[subPaths count] + 1];
18 [paths addObject:@""];
19 [paths addObjectsFromArray:subPaths];
26 for (NSString* currPath in paths) {
27 NSString* child = [rootPath stringByAppendingPathComponent:currPath];
29 NSDictionary* attributes = [fileManager attributesOfItemAtPath:child error:&error];
35 // Don't check for writability of files pointed to by symlinks, as they may
36 // not be descendants of the root path.
37 if ([attributes fileType] != NSFileTypeSymbolicLink &&
38 [fileManager isWritableFileAtPath:child] == NO) {