diff options
author | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2010-07-26 17:00:52 +0000 |
---|---|---|
committer | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2010-07-26 17:00:52 +0000 |
commit | 5d588c34c079b3ac0333c2ef5eed6efb76b31b88 (patch) | |
tree | 294488e6da48402e4276603ef3853f39f67b9aaf /Foundation/GTMNSFileHandle+UniqueName.h | |
parent | 4d56ee54c0f2b36d0e96db4a74e1b84d539df29d (diff) |
[Author: dmaclach]
Added GTMNSFileHandle+UniqueName for easily and safely creating temporary files and
unique directory names.
Modified some tests to use the new calls.
R=thomasvl
DELTA=420 (397 added, 16 deleted, 7 changed)
Diffstat (limited to 'Foundation/GTMNSFileHandle+UniqueName.h')
-rw-r--r-- | Foundation/GTMNSFileHandle+UniqueName.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/Foundation/GTMNSFileHandle+UniqueName.h b/Foundation/GTMNSFileHandle+UniqueName.h new file mode 100644 index 0000000..38197cd --- /dev/null +++ b/Foundation/GTMNSFileHandle+UniqueName.h @@ -0,0 +1,81 @@ +// +// GTMNSFileHandle+UniqueName.h +// +// Copyright 2010 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy +// of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. +// + +#import <Foundation/Foundation.h> +#import "GTMDefines.h" + +@interface NSFileHandle (GTMFileHandleUniqueNameAdditions) + +// Creates a read/write temporary file in NSTemporaryDirectory with mode 0600. +// The template should be similar to the template passed to mkstemp. +// If there is an extension on the nameTemplate it will remain. An example +// template is "MyAppXXXXXX.txt". +// If |path| is not nil, it will contain the derived path for the file. +// The file descriptor wrapped by the NSFileHandle will be closed on dealloc. ++ (id)gtm_fileHandleForTemporaryFileBasedOn:(NSString *)nameTemplate + finalPath:(NSString **)path; + +// Return an opened read/write file handle with mode 0600 based on a template. +// The template should be similar to the template passed to mkstemp. +// If there is an extension on the pathTemplate it will remain. An example +// template is "/Applications/MyAppXXXXXX.txt". +// If |path| is not nil, it will contain the derived path for the file. +// The file descriptor wrapped by the NSFileHandle will be closed on dealloc. ++ (id)gtm_fileHandleWithUniqueNameBasedOn:(NSString *)pathTemplate + finalPath:(NSString **)path; + +// Same as fileHandleWithUniqueNameBasedOn:finalName: but splits up the +// template from the directory. ++ (id)gtm_fileHandleWithUniqueNameBasedOn:(NSString *)nameTemplate + inDirectory:(NSString *)directory + finalPath:(NSString **)path; + + +// Same as fileHandleWithUniqueNameBasedOn:inDirectory:finalName: but finds +// the directory using the |directory| and |mask| arguments. ++ (id)gtm_fileHandleWithUniqueNameBasedOn:(NSString *)nameTemplate + inDirectory:(NSSearchPathDirectory)directory + domainMask:(NSSearchPathDomainMask)mask + finalPath:(NSString **)path; +@end + +@interface NSFileManager (GTMFileManagerUniqueNameAdditions) + +// Creates a new directory in NSTemporaryDirectory with mode 0700. +// The template should be similar to the template passed to mkdtemp. +- (NSString *)gtm_createTemporaryDirectoryBasedOn:(NSString *)nameTemplate; + +// Return the path to a directory with mode 0700 based on a template. +// The template should be similar to the template passed to mkdtemp. +- (NSString *)gtm_createDirectoryWithUniqueNameBasedOn:(NSString *)nameTemplate; + +// Same as createDirectoryWithUniqueNameBasedOn: but splits up the +// template from the directory. +- (NSString *)gtm_createDirectoryWithUniqueNameBasedOn:(NSString *)pathTemplate + inDirectory:(NSString *)directory; + +// Same as createDirectoryWithUniqueNameBasedOn:inDirectory: but finds +// the directory using the |directory| and |mask| arguments. +- (NSString *)gtm_createDirectoryWithUniqueNameBasedOn:(NSString *)pathTemplate + inDirectory:(NSSearchPathDirectory)directory + domainMask:(NSSearchPathDomainMask)mask; +@end + +// Same template as you would pass to mktemp. Note that this has the same +// potential race conditions for use with file creation as mktemp does. +GTM_EXTERN NSString *GTMUniqueFileObjectPathBasedOn(NSString *pathTemplate); |