/core/externals/update-engine/externals/google-toolbox-for-mac/Foundation/GTMPath.h

http://macfuse.googlecode.com/ · C++ Header · 136 lines · 27 code · 18 blank · 91 comment · 0 complexity · e3e07ef323a89e251622e2ee95202946 MD5 · raw file

  1. //
  2. // GTMPath.h
  3. //
  4. // Copyright 2007-2008 Google Inc.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. // use this file except in compliance with the License. You may obtain a copy
  8. // of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. // License for the specific language governing permissions and limitations under
  16. // the License.
  17. //
  18. #import <Foundation/Foundation.h>
  19. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  20. // NSFileManager has improved substantially in Leopard and beyond, so GTMPath
  21. // is now deprecated.
  22. // GTMPath
  23. //
  24. // This class represents a single, absolute file system path. The represented
  25. // path must exist at the time of creation. This class also allows you to easily
  26. // create new paths (or full hierarchies) based on existing GTMPath instances.
  27. //
  28. // Given a GTMPath instance, new files and directories can be created inside
  29. // that path providing the instance refers to a directory. It is an error to try
  30. // to create a file/directory from a GTMPath that represents a file (this should
  31. // be common sense: clearly mkdir /etc/passwd/foo won't work).
  32. //
  33. // === Examples ===
  34. //
  35. // 1. This sample creates a GTMPath that references /tmp, then gets the
  36. // attributes for that directory.
  37. //
  38. // GTMPath *tmp = [GTMPath pathWithFullPath:@"/tmp"];
  39. // NSDictionary *attr = [tmp attributes];
  40. //
  41. //
  42. // 2. This sample creates a new directory inside /tmp named "foo".
  43. //
  44. // GTMPath *tmp = [GTMPath pathWithFullPath:@"/tmp"];
  45. // GTMPath *foo = [tmp createDirectoryName:@"foo" mode:0755];
  46. //
  47. //
  48. // 3. This sample creates a GTMPath instance that represents a user's ~/Library
  49. // folder.
  50. //
  51. // GTMPath *library = [GTMPath pathWithFullPath:@"/Users/bob/Library"];
  52. // ...
  53. //
  54. //
  55. // 4. This sample creates a directory hierarchy, where each level has its own
  56. // mode. Notice that the return value from these -create* methods is the
  57. // GTMPath that was just created. This allows these creation calls to be
  58. // chained together enabling easy creation of directory hierarchies.
  59. // This is one of the big benefits of this class.
  60. //
  61. // GTMPath *tmp = [GTMPath pathWithFullPath:@"/tmp"];
  62. // GTMPath *baz = [[[tmp createDirectoryName:@"foo" mode:0755]
  63. // createDirectoryName:@"bar" mode:0756]
  64. // createDirectoryName:@"baz" mode:0757];
  65. //
  66. @interface GTMPath : NSObject {
  67. @private
  68. NSString *fullPath_;
  69. }
  70. // Returns a GTMPath instance that represents the full path specified by
  71. // |fullPath|. Note that |fullPath| MUST be an absolute path.
  72. + (id)pathWithFullPath:(NSString *)fullPath;
  73. // Returns a GTMPath instance that represents the full path specified by
  74. // |fullPath|. Note that |fullPath| MUST be an absolute path. This method is the
  75. // designated initializer.
  76. - (id)initWithFullPath:(NSString *)fullPath;
  77. // Returns the name of this GTMPath instance. This is not the full path. It is
  78. // just the component name of this GTMPath instance. This is equivalent to
  79. // the Unix basename(3) function.
  80. - (NSString *)name;
  81. // Returns this path's parent GTMPath. This method will ONLY (and always) return
  82. // nil when |name| is "/". In otherwords, parent will be nil IFF this GTMPath
  83. // instance represents the root path, because "/" doesn't really have a parent.
  84. - (GTMPath *)parent;
  85. // Returns YES if this GTMPath represents a directory.
  86. - (BOOL)isDirectory;
  87. // Returns YES if this GTMPath instance represents the root path "/".
  88. - (BOOL)isRoot;
  89. // Returns the file system attributes of the path represented by this GTMPath
  90. // instance. See -[NSFileManager fileAttributesAtPath:...] for details.
  91. - (NSDictionary *)attributes;
  92. // Returns a string representation of the absolute path represented by this
  93. // GTMPath instance.
  94. - (NSString *)fullPath;
  95. @end
  96. // Methods for creating files and directories inside a GTMPath instance. These
  97. // methods are only allowed to be called on GTMPath instances that represent
  98. // directories. See the NSFileManager documentation for details about the
  99. // |attributes| parameters.
  100. @interface GTMPath (GTMPathGeneration)
  101. // Creates a new directory with the specified mode or attributes inside the
  102. // current GTMPath instance. If the creation is successful, a GTMPath for the
  103. // newly created directory is returned. Otherwise, nil is returned.
  104. - (GTMPath *)createDirectoryName:(NSString *)name mode:(mode_t)mode;
  105. - (GTMPath *)createDirectoryName:(NSString *)name
  106. attributes:(NSDictionary *)attributes;
  107. // Creates a new file with the specified mode or attributes inside the
  108. // current GTMPath instance. If the creation is successful, a GTMPath for the
  109. // newly created file is returned. Otherwise, nil is returned. |data| is the
  110. // data to put in the file when created.
  111. - (GTMPath *)createFileName:(NSString *)name mode:(mode_t)mode;
  112. - (GTMPath *)createFileName:(NSString *)name
  113. attributes:(NSDictionary *)attributes;
  114. - (GTMPath *)createFileName:(NSString *)name
  115. attributes:(NSDictionary *)attributes
  116. data:(NSData *)data;
  117. @end
  118. #endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5