Bug 1865172 Part 1 - Always store a page name value when a breakpoint is first found...
[gecko.git] / toolkit / xre / updaterfileutils_osx.mm
blob25f14f3734f9eba52a4a1171fc894d8c1cb22ee9
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];
15   NSError* error = nil;
16   NSArray* subPaths = [fileManager subpathsOfDirectoryAtPath:rootPath
17                                                        error:&error];
18   NSMutableArray* paths =
19       [NSMutableArray arrayWithCapacity:[subPaths count] + 1];
20   [paths addObject:@""];
21   [paths addObjectsFromArray:subPaths];
23   if (error) {
24     [pool drain];
25     return false;
26   }
28   for (NSString* currPath in paths) {
29     NSString* child = [rootPath stringByAppendingPathComponent:currPath];
31     NSDictionary* attributes = [fileManager attributesOfItemAtPath:child
32                                                              error:&error];
33     if (error) {
34       [pool drain];
35       return false;
36     }
38     // Don't check for writability of files pointed to by symlinks, as they may
39     // not be descendants of the root path.
40     if ([attributes fileType] != NSFileTypeSymbolicLink &&
41         [fileManager isWritableFileAtPath:child] == NO) {
42       [pool drain];
43       return false;
44     }
45   }
47   [pool drain];
48   return true;