Bug 1835241 - Part 6: Use the same parameter names at definition and declaration...
[gecko.git] / toolkit / xre / updaterfileutils_osx.mm
blob15a4b3a5bacf5310011de2fcdf4c245d2e2e628d
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 error:&error];
17   NSMutableArray* paths = [NSMutableArray arrayWithCapacity:[subPaths count] + 1];
18   [paths addObject:@""];
19   [paths addObjectsFromArray:subPaths];
21   if (error) {
22     [pool drain];
23     return false;
24   }
26   for (NSString* currPath in paths) {
27     NSString* child = [rootPath stringByAppendingPathComponent:currPath];
29     NSDictionary* attributes = [fileManager attributesOfItemAtPath:child error:&error];
30     if (error) {
31       [pool drain];
32       return false;
33     }
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) {
39       [pool drain];
40       return false;
41     }
42   }
44   [pool drain];
45   return true;