From 952e076084082c95fe2029b244fcc301f66f3339 Mon Sep 17 00:00:00 2001 From: Marco Rebhan Date: Mon, 10 Jun 2024 20:40:39 +0200 Subject: [PATCH] Implement -[NSFileManager URLsForDirectory:inDomains:] --- ChangeLog | 6 ++++++ Headers/Foundation/NSFileManager.h | 15 +++++++++++++++ MISSING | 1 - Source/NSFileManager.m | 15 +++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index af79f2773..b8501cbf0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2024-06-10 Marco Rebhan + + * Headers/Foundation/NSFileManager.h: + * Source/NSFileManager.m: + Implement -[NSFileManager URLsForDirectory:inDomains:]. + 2024-06-10 Richard Frith-Macdonald * Source/GSFileHandle.m: debug log of closing a closed file handle diff --git a/Headers/Foundation/NSFileManager.h b/Headers/Foundation/NSFileManager.h index 22c029cac..e76fddf5f 100644 --- a/Headers/Foundation/NSFileManager.h +++ b/Headers/Foundation/NSFileManager.h @@ -356,6 +356,21 @@ GS_EXPORT_CLASS create: (BOOL)shouldCreate error: (NSError **)error; +/** + * Returns an array of search paths to look at for resources.
+ * The paths are returned in domain order: + * USER, LOCAL, NETWORK then SYSTEM.
+ * The presence of a path in this list does not mean that the + * path actually exists in the filesystem.
+ * If you are wanting to locate an existing resource, you should normally + * call this method with NSAllDomainsMask, but if you wish to find the + * path in which you should create a new file, you would generally + * specify a particular domain, and then create the path in the file + * system if it does not already exist. + */ +- (GS_GENERIC_CLASS(NSArray, NSURL *) *)URLsForDirectory: (NSSearchPathDirectory)directory + inDomains: (NSSearchPathDomainMask)domain; + /** * Enumerate over the contents of a directory. */ diff --git a/MISSING b/MISSING index 8c7fd1178..9884f4a84 100644 --- a/MISSING +++ b/MISSING @@ -200,7 +200,6 @@ NSFileManager: - mountedVolumeURLsIncludingResourceValuesForKeys:options: - contentsOfDirectoryAtURL:includingPropertiesForKeys:options:error: - - URLsForDirectory:inDomains: - createDirectoryAtURL:withIntermediateDirectories:attributes:error: - createSymbolicLinkAtURL:withDestinationURL:error: - setDelegate: diff --git a/Source/NSFileManager.m b/Source/NSFileManager.m index 1ec16a258..df2068281 100644 --- a/Source/NSFileManager.m +++ b/Source/NSFileManager.m @@ -59,6 +59,7 @@ #import "Foundation/NSSet.h" #import "Foundation/NSURL.h" #import "Foundation/NSValue.h" +#import "GSFastEnumeration.h" #import "GSPrivate.h" #import "GSPThread.h" #import "GNUstepBase/NSString+GNUstepBase.h" @@ -925,6 +926,20 @@ - (NSURL *)URLForDirectory: (NSSearchPathDirectory)directory return [NSURL fileURLWithPath: path]; } +- (GS_GENERIC_CLASS(NSArray, NSURL *) *)URLsForDirectory: (NSSearchPathDirectory)directory + inDomains: (NSSearchPathDomainMask)domain +{ + NSArray *paths = NSSearchPathForDirectoriesInDomains(directory, domain, YES); + NSMutableArray *urls = [[NSMutableArray alloc] initWithCapacity: paths.count]; + + FOR_IN(NSString *, path, paths) + [urls addObject: [NSURL fileURLWithPath: path]]; + END_FOR_IN(paths) + + RELEASE(paths); + return urls; +} + - (NSDirectoryEnumerator*) enumeratorAtURL: (NSURL*)url includingPropertiesForKeys: (NSArray*)keys options: (NSDirectoryEnumerationOptions)mask