1 //===- llvm/Support/PathV1.h - Path Operating System Concept ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the llvm::sys::Path class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SUPPORT_PATHV1_H
15 #define LLVM_SUPPORT_PATHV1_H
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Compiler.h"
19 #include "llvm/Support/TimeValue.h"
24 #define LLVM_PATH_DEPRECATED_MSG(replacement) \
25 "PathV1 has been deprecated and will be removed as soon as all LLVM and" \
26 " Clang clients have been moved over to PathV2. Please use `" #replacement \
27 "` from PathV2 instead."
32 /// This structure provides basic file system information about a file. It
33 /// is patterned after the stat(2) Unix operating system call but made
34 /// platform independent and eliminates many of the unix-specific fields.
35 /// However, to support llvm-ar, the mode, user, and group fields are
36 /// retained. These pertain to unix security and may not have a meaningful
37 /// value on non-Unix platforms. However, the other fields should
38 /// always be applicable on all platforms. The structure is filled in by
39 /// the PathWithStatus class.
40 /// @brief File status structure
43 uint64_t fileSize; ///< Size of the file in bytes
44 TimeValue modTime; ///< Time of file's modification
45 uint32_t mode; ///< Mode of the file, if applicable
46 uint32_t user; ///< User ID of owner, if applicable
47 uint32_t group; ///< Group ID of owner, if applicable
48 uint64_t uniqueID; ///< A number to uniquely ID this file
49 bool isDir : 1; ///< True if this is a directory.
50 bool isFile : 1; ///< True if this is a file.
52 FileStatus() : fileSize(0), modTime(0,0), mode(0777), user(999),
53 group(999), uniqueID(0), isDir(false), isFile(false) { }
55 TimeValue getTimestamp() const { return modTime; }
56 uint64_t getSize() const { return fileSize; }
57 uint32_t getMode() const { return mode; }
58 uint32_t getUser() const { return user; }
59 uint32_t getGroup() const { return group; }
60 uint64_t getUniqueID() const { return uniqueID; }
63 /// This class provides an abstraction for the path to a file or directory
64 /// in the operating system's filesystem and provides various basic operations
65 /// on it. Note that this class only represents the name of a path to a file
66 /// or directory which may or may not be valid for a given machine's file
67 /// system. The class is patterned after the java.io.File class with various
68 /// extensions and several omissions (not relevant to LLVM). A Path object
69 /// ensures that the path it encapsulates is syntactically valid for the
70 /// operating system it is running on but does not ensure correctness for
71 /// any particular file system. That is, a syntactically valid path might
72 /// specify path components that do not exist in the file system and using
73 /// such a Path to act on the file system could produce errors. There is one
74 /// invalid Path value which is permitted: the empty path. The class should
75 /// never allow a syntactically invalid non-empty path name to be assigned.
76 /// Empty paths are required in order to indicate an error result in some
77 /// situations. If the path is empty, the isValid operation will return
78 /// false. All operations will fail if isValid is false. Operations that
79 /// change the path will either return false if it would cause a syntactically
80 /// invalid path name (in which case the Path object is left unchanged) or
81 /// throw an std::string exception indicating the error. The methods are
82 /// grouped into four basic categories: Path Accessors (provide information
83 /// about the path without accessing disk), Disk Accessors (provide
84 /// information about the underlying file or directory), Path Mutators
85 /// (change the path information, not the disk), and Disk Mutators (change
86 /// the disk file/directory referenced by the path). The Disk Mutator methods
87 /// all have the word "disk" embedded in their method name to reinforce the
88 /// notion that the operation modifies the file system.
90 /// @brief An abstraction for operating system paths.
92 /// @name Constructors
95 /// Construct a path to the root directory of the file system. The root
96 /// directory is a top level directory above which there are no more
97 /// directories. For example, on UNIX, the root directory is /. On Windows
98 /// it is file:///. Other operating systems may have different notions of
99 /// what the root directory is or none at all. In that case, a consistent
100 /// default root directory will be used.
101 LLVM_ATTRIBUTE_DEPRECATED(static Path GetRootDirectory(),
102 LLVM_PATH_DEPRECATED_MSG(NOTHING));
104 /// Construct a path to a unique temporary directory that is created in
105 /// a "standard" place for the operating system. The directory is
106 /// guaranteed to be created on exit from this function. If the directory
107 /// cannot be created, the function will throw an exception.
108 /// @returns an invalid path (empty) on error
109 /// @param ErrMsg Optional place for an error message if an error occurs
110 /// @brief Construct a path to an new, unique, existing temporary
112 static Path GetTemporaryDirectory(std::string* ErrMsg = 0);
114 /// Construct a vector of sys::Path that contains the "standard" system
115 /// library paths suitable for linking into programs.
116 /// @brief Construct a path to the system library directory
117 static void GetSystemLibraryPaths(std::vector<sys::Path>& Paths);
119 /// Construct a path to the current user's home directory. The
120 /// implementation must use an operating system specific mechanism for
121 /// determining the user's home directory. For example, the environment
122 /// variable "HOME" could be used on Unix. If a given operating system
123 /// does not have the concept of a user's home directory, this static
124 /// constructor must provide the same result as GetRootDirectory.
125 /// @brief Construct a path to the current user's "home" directory
126 static Path GetUserHomeDirectory();
128 /// Construct a path to the current directory for the current process.
129 /// @returns The current working directory.
130 /// @brief Returns the current working directory.
131 static Path GetCurrentDirectory();
133 /// Return the suffix commonly used on file names that contain an
135 /// @returns The executable file suffix for the current platform.
136 /// @brief Return the executable file suffix.
137 static StringRef GetEXESuffix();
139 /// Return the suffix commonly used on file names that contain a shared
140 /// object, shared archive, or dynamic link library. Such files are
141 /// linked at runtime into a process and their code images are shared
142 /// between processes.
143 /// @returns The dynamic link library suffix for the current platform.
144 /// @brief Return the dynamic link library suffix.
145 static StringRef GetDLLSuffix();
147 /// GetMainExecutable - Return the path to the main executable, given the
148 /// value of argv[0] from program startup and the address of main itself.
149 /// In extremis, this function may fail and return an empty path.
150 static Path GetMainExecutable(const char *argv0, void *MainAddr);
152 /// This is one of the very few ways in which a path can be constructed
153 /// with a syntactically invalid name. The only *legal* invalid name is an
154 /// empty one. Other invalid names are not permitted. Empty paths are
155 /// provided so that they can be used to indicate null or error results in
156 /// other lib/System functionality.
157 /// @brief Construct an empty (and invalid) path.
159 Path(const Path &that) : path(that.path) {}
161 /// This constructor will accept a char* or std::string as a path. No
162 /// checking is done on this path to determine if it is valid. To
163 /// determine validity of the path, use the isValid method.
164 /// @param p The path to assign.
165 /// @brief Construct a Path from a string.
166 explicit Path(StringRef p);
168 /// This constructor will accept a character range as a path. No checking
169 /// is done on this path to determine if it is valid. To determine
170 /// validity of the path, use the isValid method.
171 /// @param StrStart A pointer to the first character of the path name
172 /// @param StrLen The length of the path name at StrStart
173 /// @brief Construct a Path from a string.
174 Path(const char *StrStart, unsigned StrLen);
180 /// Makes a copy of \p that to \p this.
182 /// @brief Assignment Operator
183 Path &operator=(const Path &that) {
188 /// Makes a copy of \p that to \p this.
189 /// @param that A StringRef denoting the path
191 /// @brief Assignment Operator
192 Path &operator=(StringRef that);
194 /// Compares \p this Path with \p that Path for equality.
195 /// @returns true if \p this and \p that refer to the same thing.
196 /// @brief Equality Operator
197 bool operator==(const Path &that) const;
199 /// Compares \p this Path with \p that Path for inequality.
200 /// @returns true if \p this and \p that refer to different things.
201 /// @brief Inequality Operator
202 bool operator!=(const Path &that) const { return !(*this == that); }
204 /// Determines if \p this Path is less than \p that Path. This is required
205 /// so that Path objects can be placed into ordered collections (e.g.
206 /// std::map). The comparison is done lexicographically as defined by
207 /// the std::string::compare method.
208 /// @returns true if \p this path is lexicographically less than \p that.
209 /// @brief Less Than Operator
210 bool operator<(const Path& that) const;
213 /// @name Path Accessors
216 /// This function will use an operating system specific algorithm to
217 /// determine if the current value of \p this is a syntactically valid
218 /// path name for the operating system. The path name does not need to
219 /// exist, validity is simply syntactical. Empty paths are always invalid.
220 /// @returns true iff the path name is syntactically legal for the
221 /// host operating system.
222 /// @brief Determine if a path is syntactically valid or not.
223 bool isValid() const;
225 /// This function determines if the contents of the path name are empty.
226 /// That is, the path name has a zero length. This does NOT determine if
227 /// if the file is empty. To get the length of the file itself, Use the
228 /// PathWithStatus::getFileStatus() method and then the getSize() method
229 /// on the returned FileStatus object.
230 /// @returns true iff the path is empty.
231 /// @brief Determines if the path name is empty (invalid).
232 bool isEmpty() const { return path.empty(); }
234 /// This function returns the last component of the path name. The last
235 /// component is the file or directory name occurring after the last
236 /// directory separator. If no directory separator is present, the entire
237 /// path name is returned (i.e. same as toString).
238 /// @returns StringRef containing the last component of the path name.
239 /// @brief Returns the last component of the path name.
240 LLVM_ATTRIBUTE_DEPRECATED(
241 StringRef getLast() const,
242 LLVM_PATH_DEPRECATED_MSG(path::filename));
244 /// This function strips off the path and suffix of the file or directory
245 /// name and returns just the basename. For example /a/foo.bar would cause
246 /// this function to return "foo".
247 /// @returns StringRef containing the basename of the path
248 /// @brief Get the base name of the path
249 LLVM_ATTRIBUTE_DEPRECATED(StringRef getBasename() const,
250 LLVM_PATH_DEPRECATED_MSG(path::stem));
252 /// This function strips off the suffix of the path beginning with the
253 /// path separator ('/' on Unix, '\' on Windows) and returns the result.
254 LLVM_ATTRIBUTE_DEPRECATED(StringRef getDirname() const,
255 LLVM_PATH_DEPRECATED_MSG(path::parent_path));
257 /// This function strips off the path and basename(up to and
258 /// including the last dot) of the file or directory name and
259 /// returns just the suffix. For example /a/foo.bar would cause
260 /// this function to return "bar".
261 /// @returns StringRef containing the suffix of the path
262 /// @brief Get the suffix of the path
263 LLVM_ATTRIBUTE_DEPRECATED(StringRef getSuffix() const,
264 LLVM_PATH_DEPRECATED_MSG(path::extension));
266 /// Obtain a 'C' string for the path name.
267 /// @returns a 'C' string containing the path name.
268 /// @brief Returns the path as a C string.
269 const char *c_str() const { return path.c_str(); }
270 const std::string &str() const { return path; }
273 /// size - Return the length in bytes of this path name.
274 size_t size() const { return path.size(); }
276 /// empty - Returns true if the path is empty.
277 unsigned empty() const { return path.empty(); }
280 /// @name Disk Accessors
283 /// This function determines if the path name is absolute, as opposed to
285 /// @brief Determine if the path is absolute.
286 LLVM_ATTRIBUTE_DEPRECATED(
287 bool isAbsolute() const,
288 LLVM_PATH_DEPRECATED_MSG(path::is_absolute));
290 /// This function determines if the path name is absolute, as opposed to
292 /// @brief Determine if the path is absolute.
293 LLVM_ATTRIBUTE_DEPRECATED(
294 static bool isAbsolute(const char *NameStart, unsigned NameLen),
295 LLVM_PATH_DEPRECATED_MSG(path::is_absolute));
297 /// This function opens the file associated with the path name provided by
298 /// the Path object and reads its magic number. If the magic number at the
299 /// start of the file matches \p magic, true is returned. In all other
300 /// cases (file not found, file not accessible, etc.) it returns false.
301 /// @returns true if the magic number of the file matches \p magic.
302 /// @brief Determine if file has a specific magic number
303 LLVM_ATTRIBUTE_DEPRECATED(bool hasMagicNumber(StringRef magic) const,
304 LLVM_PATH_DEPRECATED_MSG(fs::has_magic));
306 /// This function retrieves the first \p len bytes of the file associated
307 /// with \p this. These bytes are returned as the "magic number" in the
308 /// \p Magic parameter.
309 /// @returns true if the Path is a file and the magic number is retrieved,
311 /// @brief Get the file's magic number.
312 bool getMagicNumber(std::string& Magic, unsigned len) const;
314 /// This function determines if the path name in the object references an
315 /// archive file by looking at its magic number.
316 /// @returns true if the file starts with the magic number for an archive
318 /// @brief Determine if the path references an archive file.
319 bool isArchive() const;
321 /// This function determines if the path name in the object references an
322 /// LLVM Bitcode file by looking at its magic number.
323 /// @returns true if the file starts with the magic number for LLVM
325 /// @brief Determine if the path references a bitcode file.
326 bool isBitcodeFile() const;
328 /// This function determines if the path name in the object references a
329 /// native Dynamic Library (shared library, shared object) by looking at
330 /// the file's magic number. The Path object must reference a file, not a
332 /// @returns true if the file starts with the magic number for a native
334 /// @brief Determine if the path references a dynamic library.
335 bool isDynamicLibrary() const;
337 /// This function determines if the path name in the object references a
338 /// native object file by looking at it's magic number. The term object
339 /// file is defined as "an organized collection of separate, named
340 /// sequences of binary data." This covers the obvious file formats such
341 /// as COFF and ELF, but it also includes llvm ir bitcode, archives,
342 /// libraries, etc...
343 /// @returns true if the file starts with the magic number for an object
345 /// @brief Determine if the path references an object file.
346 bool isObjectFile() const;
348 /// This function determines if the path name references an existing file
349 /// or directory in the file system.
350 /// @returns true if the pathname references an existing file or
352 /// @brief Determines if the path is a file or directory in
354 LLVM_ATTRIBUTE_DEPRECATED(bool exists() const,
355 LLVM_PATH_DEPRECATED_MSG(fs::exists));
357 /// This function determines if the path name references an
358 /// existing directory.
359 /// @returns true if the pathname references an existing directory.
360 /// @brief Determines if the path is a directory in the file system.
361 LLVM_ATTRIBUTE_DEPRECATED(bool isDirectory() const,
362 LLVM_PATH_DEPRECATED_MSG(fs::is_directory));
364 /// This function determines if the path name references an
365 /// existing symbolic link.
366 /// @returns true if the pathname references an existing symlink.
367 /// @brief Determines if the path is a symlink in the file system.
368 LLVM_ATTRIBUTE_DEPRECATED(bool isSymLink() const,
369 LLVM_PATH_DEPRECATED_MSG(fs::is_symlink));
371 /// This function determines if the path name references a readable file
372 /// or directory in the file system. This function checks for
373 /// the existence and readability (by the current program) of the file
375 /// @returns true if the pathname references a readable file.
376 /// @brief Determines if the path is a readable file or directory
377 /// in the file system.
378 bool canRead() const;
380 /// This function determines if the path name references a writable file
381 /// or directory in the file system. This function checks for the
382 /// existence and writability (by the current program) of the file or
384 /// @returns true if the pathname references a writable file.
385 /// @brief Determines if the path is a writable file or directory
386 /// in the file system.
387 bool canWrite() const;
389 /// This function checks that what we're trying to work only on a regular
390 /// file. Check for things like /dev/null, any block special file, or
391 /// other things that aren't "regular" regular files.
392 /// @returns true if the file is S_ISREG.
393 /// @brief Determines if the file is a regular file
394 bool isRegularFile() const;
396 /// This function determines if the path name references an executable
397 /// file in the file system. This function checks for the existence and
398 /// executability (by the current program) of the file.
399 /// @returns true if the pathname references an executable file.
400 /// @brief Determines if the path is an executable file in the file
402 bool canExecute() const;
404 /// This function builds a list of paths that are the names of the
405 /// files and directories in a directory.
406 /// @returns true if an error occurs, true otherwise
407 /// @brief Build a list of directory's contents.
408 bool getDirectoryContents(
409 std::set<Path> &paths, ///< The resulting list of file & directory names
410 std::string* ErrMsg ///< Optional place to return an error message.
414 /// @name Path Mutators
417 /// The path name is cleared and becomes empty. This is an invalid
418 /// path name but is the *only* invalid path name. This is provided
419 /// so that path objects can be used to indicate the lack of a
420 /// valid path being found.
421 /// @brief Make the path empty.
422 void clear() { path.clear(); }
424 /// This method sets the Path object to \p unverified_path. This can fail
425 /// if the \p unverified_path does not pass the syntactic checks of the
426 /// isValid() method. If verification fails, the Path object remains
427 /// unchanged and false is returned. Otherwise true is returned and the
428 /// Path object takes on the path value of \p unverified_path
429 /// @returns true if the path was set, false otherwise.
430 /// @param unverified_path The path to be set in Path object.
431 /// @brief Set a full path from a StringRef
432 bool set(StringRef unverified_path);
434 /// One path component is removed from the Path. If only one component is
435 /// present in the path, the Path object becomes empty. If the Path object
436 /// is empty, no change is made.
437 /// @returns false if the path component could not be removed.
438 /// @brief Removes the last directory component of the Path.
439 bool eraseComponent();
441 /// The \p component is added to the end of the Path if it is a legal
442 /// name for the operating system. A directory separator will be added if
444 /// @returns false if the path component could not be added.
445 /// @brief Appends one path component to the Path.
446 bool appendComponent(StringRef component);
448 /// A period and the \p suffix are appended to the end of the pathname.
449 /// When the \p suffix is empty, no action is performed.
450 /// @brief Adds a period and the \p suffix to the end of the pathname.
451 void appendSuffix(StringRef suffix);
453 /// The suffix of the filename is erased. The suffix begins with and
454 /// includes the last . character in the filename after the last directory
455 /// separator and extends until the end of the name. If no . character is
456 /// after the last directory separator, then the file name is left
457 /// unchanged (i.e. it was already without a suffix) but the function
459 /// @returns false if there was no suffix to remove, true otherwise.
460 /// @brief Remove the suffix from a path name.
463 /// The current Path name is made unique in the file system. Upon return,
464 /// the Path will have been changed to make a unique file in the file
465 /// system or it will not have been changed if the current path name is
467 /// @throws std::string if an unrecoverable error occurs.
468 /// @brief Make the current path name unique in the file system.
469 bool makeUnique( bool reuse_current /*= true*/, std::string* ErrMsg );
471 /// The current Path name is made absolute by prepending the
472 /// current working directory if necessary.
473 LLVM_ATTRIBUTE_DEPRECATED(
475 LLVM_PATH_DEPRECATED_MSG(fs::make_absolute));
478 /// @name Disk Mutators
481 /// This method attempts to make the file referenced by the Path object
482 /// available for reading so that the canRead() method will return true.
483 /// @brief Make the file readable;
484 bool makeReadableOnDisk(std::string* ErrMsg = 0);
486 /// This method attempts to make the file referenced by the Path object
487 /// available for writing so that the canWrite() method will return true.
488 /// @brief Make the file writable;
489 bool makeWriteableOnDisk(std::string* ErrMsg = 0);
491 /// This method attempts to make the file referenced by the Path object
492 /// available for execution so that the canExecute() method will return
494 /// @brief Make the file readable;
495 bool makeExecutableOnDisk(std::string* ErrMsg = 0);
497 /// This method allows the last modified time stamp and permission bits
498 /// to be set on the disk object referenced by the Path.
499 /// @throws std::string if an error occurs.
500 /// @returns true on error.
501 /// @brief Set the status information.
502 bool setStatusInfoOnDisk(const FileStatus &SI,
503 std::string *ErrStr = 0) const;
505 /// This method attempts to create a directory in the file system with the
506 /// same name as the Path object. The \p create_parents parameter controls
507 /// whether intermediate directories are created or not. if \p
508 /// create_parents is true, then an attempt will be made to create all
509 /// intermediate directories, as needed. If \p create_parents is false,
510 /// then only the final directory component of the Path name will be
511 /// created. The created directory will have no entries.
512 /// @returns true if the directory could not be created, false otherwise
513 /// @brief Create the directory this Path refers to.
514 bool createDirectoryOnDisk(
515 bool create_parents = false, ///< Determines whether non-existent
516 ///< directory components other than the last one (the "parents")
517 ///< are created or not.
518 std::string* ErrMsg = 0 ///< Optional place to put error messages.
521 /// This method attempts to create a file in the file system with the same
522 /// name as the Path object. The intermediate directories must all exist
523 /// at the time this method is called. Use createDirectoriesOnDisk to
524 /// accomplish that. The created file will be empty upon return from this
526 /// @returns true if the file could not be created, false otherwise.
527 /// @brief Create the file this Path refers to.
528 bool createFileOnDisk(
529 std::string* ErrMsg = 0 ///< Optional place to put error messages.
532 /// This is like createFile except that it creates a temporary file. A
533 /// unique temporary file name is generated based on the contents of
534 /// \p this before the call. The new name is assigned to \p this and the
535 /// file is created. Note that this will both change the Path object
536 /// *and* create the corresponding file. This function will ensure that
537 /// the newly generated temporary file name is unique in the file system.
538 /// @returns true if the file couldn't be created, false otherwise.
539 /// @brief Create a unique temporary file
540 bool createTemporaryFileOnDisk(
541 bool reuse_current = false, ///< When set to true, this parameter
542 ///< indicates that if the current file name does not exist then
543 ///< it will be used without modification.
544 std::string* ErrMsg = 0 ///< Optional place to put error messages
547 /// This method renames the file referenced by \p this as \p newName. The
548 /// file referenced by \p this must exist. The file referenced by
549 /// \p newName does not need to exist.
550 /// @returns true on error, false otherwise
551 /// @brief Rename one file as another.
552 bool renamePathOnDisk(const Path& newName, std::string* ErrMsg);
554 /// This method attempts to destroy the file or directory named by the
555 /// last component of the Path. If the Path refers to a directory and the
556 /// \p destroy_contents is false, an attempt will be made to remove just
557 /// the directory (the final Path component). If \p destroy_contents is
558 /// true, an attempt will be made to remove the entire contents of the
559 /// directory, recursively. If the Path refers to a file, the
560 /// \p destroy_contents parameter is ignored.
561 /// @param destroy_contents Indicates whether the contents of a destroyed
562 /// @param Err An optional string to receive an error message.
563 /// directory should also be destroyed (recursively).
564 /// @returns false if the file/directory was destroyed, true on error.
565 /// @brief Removes the file or directory from the filesystem.
566 bool eraseFromDisk(bool destroy_contents = false,
567 std::string *Err = 0) const;
570 /// MapInFilePages - This is a low level system API to map in the file
571 /// that is currently opened as FD into the current processes' address
572 /// space for read only access. This function may return null on failure
573 /// or if the system cannot provide the following constraints:
574 /// 1) The pages must be valid after the FD is closed, until
575 /// UnMapFilePages is called.
576 /// 2) Any padding after the end of the file must be zero filled, if
578 /// 3) The pages must be contiguous.
580 /// This API is not intended for general use, clients should use
581 /// MemoryBuffer::getFile instead.
582 static const char *MapInFilePages(int FD, size_t FileSize,
585 /// UnMapFilePages - Free pages mapped into the current process by
588 /// This API is not intended for general use, clients should use
589 /// MemoryBuffer::getFile instead.
590 static void UnMapFilePages(const char *Base, size_t FileSize);
596 // Our win32 implementation relies on this string being mutable.
597 mutable std::string path; ///< Storage for the path name.
603 /// This class is identical to Path class except it allows you to obtain the
604 /// file status of the Path as well. The reason for the distinction is one of
605 /// efficiency. First, the file status requires additional space and the space
606 /// is incorporated directly into PathWithStatus without an additional malloc.
607 /// Second, obtaining status information is an expensive operation on most
608 /// operating systems so we want to be careful and explicit about where we
609 /// allow this operation in LLVM.
610 /// @brief Path with file status class.
611 class PathWithStatus : public Path {
612 /// @name Constructors
615 /// @brief Default constructor
616 PathWithStatus() : Path(), status(), fsIsValid(false) {}
618 /// @brief Copy constructor
619 PathWithStatus(const PathWithStatus &that)
620 : Path(static_cast<const Path&>(that)), status(that.status),
621 fsIsValid(that.fsIsValid) {}
623 /// This constructor allows construction from a Path object
624 /// @brief Path constructor
625 PathWithStatus(const Path &other)
626 : Path(other), status(), fsIsValid(false) {}
628 /// This constructor will accept a char* or std::string as a path. No
629 /// checking is done on this path to determine if it is valid. To
630 /// determine validity of the path, use the isValid method.
631 /// @brief Construct a Path from a string.
632 explicit PathWithStatus(
633 StringRef p ///< The path to assign.
634 ) : Path(p), status(), fsIsValid(false) {}
636 /// This constructor will accept a character range as a path. No checking
637 /// is done on this path to determine if it is valid. To determine
638 /// validity of the path, use the isValid method.
639 /// @brief Construct a Path from a string.
640 explicit PathWithStatus(
641 const char *StrStart, ///< Pointer to the first character of the path
642 unsigned StrLen ///< Length of the path.
643 ) : Path(StrStart, StrLen), status(), fsIsValid(false) {}
645 /// Makes a copy of \p that to \p this.
647 /// @brief Assignment Operator
648 PathWithStatus &operator=(const PathWithStatus &that) {
649 static_cast<Path&>(*this) = static_cast<const Path&>(that);
650 status = that.status;
651 fsIsValid = that.fsIsValid;
655 /// Makes a copy of \p that to \p this.
657 /// @brief Assignment Operator
658 PathWithStatus &operator=(const Path &that) {
659 static_cast<Path&>(*this) = static_cast<const Path&>(that);
668 /// This function returns status information about the file. The type of
669 /// path (file or directory) is updated to reflect the actual contents
670 /// of the file system.
671 /// @returns 0 on failure, with Error explaining why (if non-zero),
672 /// otherwise returns a pointer to a FileStatus structure on success.
673 /// @brief Get file status.
674 const FileStatus *getFileStatus(
675 bool forceUpdate = false, ///< Force an update from the file system
676 std::string *Error = 0 ///< Optional place to return an error msg.
683 mutable FileStatus status; ///< Status information.
684 mutable bool fsIsValid; ///< Whether we've obtained it or not
689 /// This function can be used to copy the file specified by Src to the
690 /// file specified by Dest. If an error occurs, Dest is removed.
691 /// @returns true if an error occurs, false otherwise
692 /// @brief Copy one file to another.
693 bool CopyFile(const Path& Dest, const Path& Src, std::string* ErrMsg);
695 /// This is the OS-specific path separator: a colon on Unix or a semicolon
697 extern const char PathSeparator;