add missing ctor
[oota-llvm.git] / include / llvm / System / Path.h
1 //===- llvm/System/Path.h - Path Operating System Concept -------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the llvm::sys::Path class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SYSTEM_PATH_H
15 #define LLVM_SYSTEM_PATH_H
16
17 #include "llvm/System/TimeValue.h"
18 #include "llvm/System/IncludeFile.h"
19 #include <set>
20 #include <string>
21 #include <vector>
22 #include <iosfwd>
23
24 namespace llvm {
25 namespace sys {
26
27   /// This structure provides basic file system information about a file. It
28   /// is patterned after the stat(2) Unix operating system call but made
29   /// platform independent and eliminates many of the unix-specific fields.
30   /// However, to support llvm-ar, the mode, user, and group fields are
31   /// retained. These pertain to unix security and may not have a meaningful
32   /// value on non-Unix platforms. However, the other fields fields should 
33   /// always be applicable on all platforms.  The structure is filled in by 
34   /// the PathWithStatus class.
35   /// @brief File status structure
36   class FileStatus {
37   public:
38     uint64_t    fileSize;   ///< Size of the file in bytes
39     TimeValue   modTime;    ///< Time of file's modification
40     uint32_t    mode;       ///< Mode of the file, if applicable
41     uint32_t    user;       ///< User ID of owner, if applicable
42     uint32_t    group;      ///< Group ID of owner, if applicable
43     uint64_t    uniqueID;   ///< A number to uniquely ID this file
44     bool        isDir  : 1; ///< True if this is a directory.
45     bool        isFile : 1; ///< True if this is a file.
46
47     FileStatus() : fileSize(0), modTime(0,0), mode(0777), user(999),
48                    group(999), uniqueID(0), isDir(false), isFile(false) { }
49     
50     TimeValue getTimestamp() const { return modTime; }
51     uint64_t getSize() const { return fileSize; }
52     uint32_t getMode() const { return mode; }
53     uint32_t getUser() const { return user; }
54     uint32_t getGroup() const { return group; }
55     uint64_t getUniqueID() const { return uniqueID; }
56   };
57
58   /// This class provides an abstraction for the path to a file or directory
59   /// in the operating system's filesystem and provides various basic operations
60   /// on it.  Note that this class only represents the name of a path to a file
61   /// or directory which may or may not be valid for a given machine's file
62   /// system. The class is patterned after the java.io.File class with various
63   /// extensions and several omissions (not relevant to LLVM).  A Path object
64   /// ensures that the path it encapsulates is syntactically valid for the
65   /// operating system it is running on but does not ensure correctness for
66   /// any particular file system. That is, a syntactically valid path might
67   /// specify path components that do not exist in the file system and using
68   /// such a Path to act on the file system could produce errors. There is one
69   /// invalid Path value which is permitted: the empty path.  The class should
70   /// never allow a syntactically invalid non-empty path name to be assigned.
71   /// Empty paths are required in order to indicate an error result in some
72   /// situations. If the path is empty, the isValid operation will return
73   /// false. All operations will fail if isValid is false. Operations that
74   /// change the path will either return false if it would cause a syntactically
75   /// invalid path name (in which case the Path object is left unchanged) or
76   /// throw an std::string exception indicating the error. The methods are
77   /// grouped into four basic categories: Path Accessors (provide information
78   /// about the path without accessing disk), Disk Accessors (provide
79   /// information about the underlying file or directory), Path Mutators
80   /// (change the path information, not the disk), and Disk Mutators (change
81   /// the disk file/directory referenced by the path). The Disk Mutator methods
82   /// all have the word "disk" embedded in their method name to reinforce the
83   /// notion that the operation modifies the file system.
84   /// @since 1.4
85   /// @brief An abstraction for operating system paths.
86   class Path {
87     /// @name Constructors
88     /// @{
89     public:
90       /// Construct a path to the root directory of the file system. The root
91       /// directory is a top level directory above which there are no more
92       /// directories. For example, on UNIX, the root directory is /. On Windows
93       /// it is C:\. Other operating systems may have different notions of
94       /// what the root directory is or none at all. In that case, a consistent
95       /// default root directory will be used.
96       static Path GetRootDirectory();
97
98       /// Construct a path to a unique temporary directory that is created in
99       /// a "standard" place for the operating system. The directory is
100       /// guaranteed to be created on exit from this function. If the directory
101       /// cannot be created, the function will throw an exception.
102       /// @returns an invalid path (empty) on error
103       /// @param ErrMsg Optional place for an error message if an error occurs
104       /// @brief Constrct a path to an new, unique, existing temporary
105       /// directory.
106       static Path GetTemporaryDirectory(std::string* ErrMsg = 0);
107
108       /// Construct a vector of sys::Path that contains the "standard" system
109       /// library paths suitable for linking into programs. This function *must*
110       /// return the value of LLVM_LIB_SEARCH_PATH as the first item in \p Paths
111       /// if that environment variable is set and it references a directory.
112       /// @brief Construct a path to the system library directory
113       static void GetSystemLibraryPaths(std::vector<sys::Path>& Paths);
114
115       /// Construct a vector of sys::Path that contains the "standard" bytecode
116       /// library paths suitable for linking into an llvm program. This function
117       /// *must* return the value of LLVM_LIB_SEARCH_PATH as well as the value
118       /// of LLVM_LIBDIR. It also must provide the System library paths as
119       /// returned by GetSystemLibraryPaths.
120       /// @see GetSystemLibraryPaths
121       /// @brief Construct a list of directories in which bytecode could be
122       /// found.
123       static void GetBytecodeLibraryPaths(std::vector<sys::Path>& Paths);
124
125       /// Find the path to a library using its short name. Use the system
126       /// dependent library paths to locate the library.
127       /// @brief Find a library.
128       static Path FindLibrary(std::string& short_name);
129
130       /// Construct a path to the default LLVM configuration directory. The
131       /// implementation must ensure that this is a well-known (same on many
132       /// systems) directory in which llvm configuration files exist. For
133       /// example, on Unix, the /etc/llvm directory has been selected.
134       /// @brief Construct a path to the default LLVM configuration directory
135       static Path GetLLVMDefaultConfigDir();
136
137       /// Construct a path to the LLVM installed configuration directory. The
138       /// implementation must ensure that this refers to the "etc" directory of
139       /// the LLVM installation. This is the location where configuration files
140       /// will be located for a particular installation of LLVM on a machine.
141       /// @brief Construct a path to the LLVM installed configuration directory
142       static Path GetLLVMConfigDir();
143
144       /// Construct a path to the current user's home directory. The
145       /// implementation must use an operating system specific mechanism for
146       /// determining the user's home directory. For example, the environment
147       /// variable "HOME" could be used on Unix. If a given operating system
148       /// does not have the concept of a user's home directory, this static
149       /// constructor must provide the same result as GetRootDirectory.
150       /// @brief Construct a path to the current user's "home" directory
151       static Path GetUserHomeDirectory();
152
153       /// Return the suffix commonly used on file names that contain a shared
154       /// object, shared archive, or dynamic link library. Such files are
155       /// linked at runtime into a process and their code images are shared
156       /// between processes.
157       /// @returns The dynamic link library suffix for the current platform.
158       /// @brief Return the dynamic link library suffix.
159       static std::string GetDLLSuffix();
160
161       /// This is one of the very few ways in which a path can be constructed
162       /// with a syntactically invalid name. The only *legal* invalid name is an
163       /// empty one. Other invalid names are not permitted. Empty paths are
164       /// provided so that they can be used to indicate null or error results in
165       /// other lib/System functionality.
166       /// @brief Construct an empty (and invalid) path.
167       Path() : path() {}
168       Path(const Path &that) : path(that.path) {}
169
170       /// This constructor will accept a std::string as a path. No checking is
171       /// done on this path to determine if it is valid. To determine validity
172       /// of the path, use the isValid method. 
173       /// @param p The path to assign.
174       /// @brief Construct a Path from a string.
175       explicit Path(const std::string& p) : path(p) {}
176
177       /// This constructor will accept a character range as a path.  No checking
178       /// is done on this path to determine if it is valid.  To determine
179       /// validity of the path, use the isValid method. 
180       explicit Path(const char *StrStart, unsigned StrLen)
181         : path(StrStart, StrStart+StrLen) {}
182       
183     /// @}
184     /// @name Operators
185     /// @{
186     public:
187       /// Makes a copy of \p that to \p this.
188       /// @returns \p this
189       /// @brief Assignment Operator
190       Path &operator=(const Path &that) {
191         path = that.path;
192         return *this;
193       }
194
195       /// Compares \p this Path with \p that Path for equality.
196       /// @returns true if \p this and \p that refer to the same thing.
197       /// @brief Equality Operator
198       bool operator==(const Path &that) const {
199         return 0 == path.compare(that.path);
200       }
201
202       /// Compares \p this Path with \p that Path for inequality.
203       /// @returns true if \p this and \p that refer to different things.
204       /// @brief Inequality Operator
205       bool operator!=(const Path &that) const {
206         return 0 != path.compare(that.path);
207       }
208
209       /// Determines if \p this Path is less than \p that Path. This is required
210       /// so that Path objects can be placed into ordered collections (e.g.
211       /// std::map). The comparison is done lexicographically as defined by
212       /// the std::string::compare method.
213       /// @returns true if \p this path is lexicographically less than \p that.
214       /// @brief Less Than Operator
215       bool operator<(const Path& that) const {
216         return 0 > path.compare(that.path);
217       }
218
219     /// @}
220     /// @name Path Accessors
221     /// @{
222     public:
223       /// This function will use an operating system specific algorithm to
224       /// determine if the current value of \p this is a syntactically valid
225       /// path name for the operating system. The path name does not need to
226       /// exist, validity is simply syntactical. Empty paths are always invalid.
227       /// @returns true iff the path name is syntactically legal for the
228       /// host operating system.
229       /// @brief Determine if a path is syntactically valid or not.
230       bool isValid() const;
231
232       /// This function determines if the contents of the path name are empty. 
233       /// That is, the path name has a zero length. This does NOT determine if
234       /// if the file is empty. To get the length of the file itself, Use the 
235       /// PathWithStatus::getFileStatus() method and then the getSize() method 
236       /// on the returned FileStatus object.
237       /// @returns true iff the path is empty.
238       /// @brief Determines if the path name is empty (invalid).
239       bool isEmpty() const { return path.empty(); }
240
241       /// This function returns the current contents of the path as a
242       /// std::string. This allows the underlying path string to be manipulated.
243       /// @returns std::string containing the path name.
244       /// @brief Returns the path as a std::string.
245       const std::string &toString() const { return path; }
246
247       /// This function returns the last component of the path name. The last
248       /// component is the file or directory name occuring after the last
249       /// directory separator. If no directory separator is present, the entire
250       /// path name is returned (i.e. same as toString).
251       /// @returns std::string containing the last component of the path name.
252       /// @brief Returns the last component of the path name.
253       std::string getLast() const;
254
255       /// This function strips off the path and suffix of the file or directory
256       /// name and returns just the basename. For example /a/foo.bar would cause
257       /// this function to return "foo".
258       /// @returns std::string containing the basename of the path
259       /// @brief Get the base name of the path
260       std::string getBasename() const;
261
262       /// Obtain a 'C' string for the path name.
263       /// @returns a 'C' string containing the path name.
264       /// @brief Returns the path as a C string.
265       const char *const c_str() const { return path.c_str(); }
266
267     /// @}
268     /// @name Disk Accessors
269     /// @{
270     public:
271       /// This function determines if the path name in this object references
272       /// the root (top level directory) of the file system. The details of what
273       /// is considered the "root" may vary from system to system so this method
274       /// will do the necessary checking.
275       /// @returns true iff the path name references the root directory.
276       /// @brief Determines if the path references the root directory.
277       bool isRootDirectory() const;
278
279       /// This function determines if the path name is absolute, as opposed to
280       /// relative. 
281       /// @breif Determine if the path is absolute.
282       bool isAbsolute() const;
283
284       /// This function opens the file associated with the path name provided by
285       /// the Path object and reads its magic number. If the magic number at the
286       /// start of the file matches \p magic, true is returned. In all other
287       /// cases (file not found, file not accessible, etc.) it returns false.
288       /// @returns true if the magic number of the file matches \p magic.
289       /// @brief Determine if file has a specific magic number
290       bool hasMagicNumber(const std::string& magic) const;
291
292       /// This function retrieves the first \p len bytes of the file associated
293       /// with \p this. These bytes are returned as the "magic number" in the
294       /// \p Magic parameter.
295       /// @returns true if the Path is a file and the magic number is retrieved,
296       /// false otherwise.
297       /// @brief Get the file's magic number.
298       bool getMagicNumber(std::string& Magic, unsigned len) const;
299
300       /// This function determines if the path name in the object references an
301       /// archive file by looking at its magic number.
302       /// @returns true if the file starts with the magic number for an archive
303       /// file.
304       /// @brief Determine if the path references an archive file.
305       bool isArchive() const;
306
307       /// This function determines if the path name in the object references an
308       /// LLVM Bytecode file by looking at its magic number.
309       /// @returns true if the file starts with the magic number for LLVM
310       /// bytecode files.
311       /// @brief Determine if the path references a bytecode file.
312       bool isBytecodeFile() const;
313
314       /// This function determines if the path name in the object references a
315       /// native Dynamic Library (shared library, shared object) by looking at
316       /// the file's magic number. The Path object must reference a file, not a
317       /// directory.
318       /// @return strue if the file starts with the magid number for a native
319       /// shared library.
320       /// @brief Determine if the path reference a dynamic library.
321       bool isDynamicLibrary() const;
322
323       /// This function determines if the path name references an existing file
324       /// or directory in the file system.
325       /// @returns true if the pathname references an existing file or
326       /// directory.
327       /// @brief Determines if the path is a file or directory in
328       /// the file system.
329       bool exists() const;
330
331       /// This function determines if the path name references a readable file
332       /// or directory in the file system. This function checks for
333       /// the existence and readability (by the current program) of the file
334       /// or directory.
335       /// @returns true if the pathname references a readable file.
336       /// @brief Determines if the path is a readable file or directory
337       /// in the file system.
338       bool canRead() const;
339
340       /// This function determines if the path name references a writable file
341       /// or directory in the file system. This function checks for the
342       /// existence and writability (by the current program) of the file or
343       /// directory.
344       /// @returns true if the pathname references a writable file.
345       /// @brief Determines if the path is a writable file or directory
346       /// in the file system.
347       bool canWrite() const;
348
349       /// This function determines if the path name references an executable
350       /// file in the file system. This function checks for the existence and
351       /// executability (by the current program) of the file.
352       /// @returns true if the pathname references an executable file.
353       /// @brief Determines if the path is an executable file in the file
354       /// system.
355       bool canExecute() const;
356
357       /// This function builds a list of paths that are the names of the
358       /// files and directories in a directory.
359       /// @returns true if an error occurs, true otherwise
360       /// @brief Build a list of directory's contents.
361       bool getDirectoryContents(
362         std::set<Path> &paths, ///< The resulting list of file & directory names
363         std::string* ErrMsg    ///< Optional place to return an error message.
364       ) const;
365
366     /// @}
367     /// @name Path Mutators
368     /// @{
369     public:
370       /// The path name is cleared and becomes empty. This is an invalid
371       /// path name but is the *only* invalid path name. This is provided
372       /// so that path objects can be used to indicate the lack of a
373       /// valid path being found.
374       /// @brief Make the path empty.
375       void clear() { path.clear(); }
376
377       /// This method sets the Path object to \p unverified_path. This can fail
378       /// if the \p unverified_path does not pass the syntactic checks of the
379       /// isValid() method. If verification fails, the Path object remains
380       /// unchanged and false is returned. Otherwise true is returned and the
381       /// Path object takes on the path value of \p unverified_path
382       /// @returns true if the path was set, false otherwise.
383       /// @param unverified_path The path to be set in Path object.
384       /// @brief Set a full path from a std::string
385       bool set(const std::string& unverified_path);
386
387       /// One path component is removed from the Path. If only one component is
388       /// present in the path, the Path object becomes empty. If the Path object
389       /// is empty, no change is made.
390       /// @returns false if the path component could not be removed.
391       /// @brief Removes the last directory component of the Path.
392       bool eraseComponent();
393
394       /// The \p component is added to the end of the Path if it is a legal
395       /// name for the operating system. A directory separator will be added if
396       /// needed.
397       /// @returns false if the path component could not be added.
398       /// @brief Appends one path component to the Path.
399       bool appendComponent( const std::string& component );
400
401       /// A period and the \p suffix are appended to the end of the pathname.
402       /// The precondition for this function is that the Path reference a file
403       /// name (i.e. isFile() returns true). If the Path is not a file, no
404       /// action is taken and the function returns false. If the path would
405       /// become invalid for the host operating system, false is returned.
406       /// @returns false if the suffix could not be added, true if it was.
407       /// @brief Adds a period and the \p suffix to the end of the pathname.
408       bool appendSuffix(const std::string& suffix);
409
410       /// The suffix of the filename is erased. The suffix begins with and
411       /// includes the last . character in the filename after the last directory
412       /// separator and extends until the end of the name. If no . character is
413       /// after the last directory separator, then the file name is left
414       /// unchanged (i.e. it was already without a suffix) but the function
415       /// returns false.
416       /// @returns false if there was no suffix to remove, true otherwise.
417       /// @brief Remove the suffix from a path name.
418       bool eraseSuffix();
419
420       /// The current Path name is made unique in the file system. Upon return,
421       /// the Path will have been changed to make a unique file in the file
422       /// system or it will not have been changed if the current path name is
423       /// already unique.
424       /// @throws std::string if an unrecoverable error occurs.
425       /// @brief Make the current path name unique in the file system.
426       bool makeUnique( bool reuse_current /*= true*/, std::string* ErrMsg );
427
428     /// @}
429     /// @name Disk Mutators
430     /// @{
431     public:
432       /// This method attempts to make the file referenced by the Path object
433       /// available for reading so that the canRead() method will return true.
434       /// @brief Make the file readable;
435       bool makeReadableOnDisk(std::string* ErrMsg = 0);
436
437       /// This method attempts to make the file referenced by the Path object
438       /// available for writing so that the canWrite() method will return true.
439       /// @brief Make the file writable;
440       bool makeWriteableOnDisk(std::string* ErrMsg = 0);
441
442       /// This method attempts to make the file referenced by the Path object
443       /// available for execution so that the canExecute() method will return
444       /// true.
445       /// @brief Make the file readable;
446       bool makeExecutableOnDisk(std::string* ErrMsg = 0);
447
448       /// This method allows the last modified time stamp and permission bits
449       /// to be set on the disk object referenced by the Path.
450       /// @throws std::string if an error occurs.
451       /// @returns true on error.
452       /// @brief Set the status information.
453       bool setStatusInfoOnDisk(const FileStatus &SI,
454                                std::string *ErrStr = 0) const;
455
456       /// This method attempts to create a directory in the file system with the
457       /// same name as the Path object. The \p create_parents parameter controls
458       /// whether intermediate directories are created or not. if \p
459       /// create_parents is true, then an attempt will be made to create all
460       /// intermediate directories, as needed. If \p create_parents is false,
461       /// then only the final directory component of the Path name will be
462       /// created. The created directory will have no entries.
463       /// @returns true if the directory could not be created, false otherwise
464       /// @brief Create the directory this Path refers to.
465       bool createDirectoryOnDisk( 
466         bool create_parents = false, ///<  Determines whether non-existent 
467            ///< directory components other than the last one (the "parents") 
468            ///< are created or not.
469         std::string* ErrMsg = 0 ///< Optional place to put error messages.
470       );
471
472       /// This method attempts to create a file in the file system with the same
473       /// name as the Path object. The intermediate directories must all exist
474       /// at the time this method is called. Use createDirectoriesOnDisk to
475       /// accomplish that. The created file will be empty upon return from this
476       /// function.
477       /// @returns true if the file could not be created, false otherwise.
478       /// @brief Create the file this Path refers to.
479       bool createFileOnDisk(
480         std::string* ErrMsg = 0 ///< Optional place to put error messages.
481       );
482
483       /// This is like createFile except that it creates a temporary file. A
484       /// unique temporary file name is generated based on the contents of
485       /// \p this before the call. The new name is assigned to \p this and the
486       /// file is created.  Note that this will both change the Path object
487       /// *and* create the corresponding file. This function will ensure that
488       /// the newly generated temporary file name is unique in the file system.
489       /// @returns true if the file couldn't be created, false otherwise. 
490       /// @brief Create a unique temporary file
491       bool createTemporaryFileOnDisk(
492         bool reuse_current = false, ///< When set to true, this parameter 
493           ///< indicates that if the current file name does not exist then 
494           ///< it will be used without modification.
495         std::string* ErrMsg = 0 ///< Optional place to put error messages
496       );
497
498       /// This method renames the file referenced by \p this as \p newName. The
499       /// file referenced by \p this must exist. The file referenced by
500       /// \p newName does not need to exist.
501       /// @returns true on error, false otherwise
502       /// @brief Rename one file as another.
503       bool renamePathOnDisk(const Path& newName, std::string* ErrMsg);
504
505       /// This method attempts to destroy the file or directory named by the
506       /// last component of the Path. If the Path refers to a directory and the
507       /// \p destroy_contents is false, an attempt will be made to remove just
508       /// the directory (the final Path component). If \p destroy_contents is
509       /// true, an attempt will be made to remove the entire contents of the
510       /// directory, recursively. If the Path refers to a file, the
511       /// \p destroy_contents parameter is ignored.
512       /// @param destroy_contents Indicates whether the contents of a destroyed
513       /// directory should also be destroyed (recursively).
514       /// @returns false if the file/directory was destroyed, true on error.
515       /// @brief Removes the file or directory from the filesystem.
516       bool eraseFromDisk(bool destroy_contents = false,
517                          std::string *Err = 0) const;
518     /// @}
519     /// @name Data
520     /// @{
521     protected:
522       mutable std::string path;   ///< Storage for the path name.
523
524     /// @}
525   };
526
527   /// This class is identical to Path class except it allows you to obtain the
528   /// file status of the Path as well. The reason for the distinction is one of
529   /// efficiency. First, the file status requires additional space and the space
530   /// is incorporated directly into PathWithStatus without an additional malloc.
531   /// Second, obtaining status information is an expensive operation on most
532   /// operating systems so we want to be careful and explicity about where we
533   /// allow this operation in LLVM.
534   /// @brief Path with file status class.
535   class PathWithStatus : public Path {
536     /// @name Constructors
537     /// @{
538     public: 
539       /// @brief Default constructor
540       PathWithStatus() : Path(), status(), fsIsValid(false) {}
541
542       /// @brief Copy constructor
543       PathWithStatus(const PathWithStatus &that) 
544         : Path(static_cast<const Path&>(that)), status(that.status), 
545            fsIsValid(that.fsIsValid) {}
546
547       /// This constructor allows construction from a Path object
548       /// @brief Path constructor
549       PathWithStatus(const Path &other) 
550         : Path(other), status(), fsIsValid(false) {}
551
552       /// This constructor will accept a character range as a path.  No checking
553       /// is done on this path to determine if it is valid.  To determine
554       /// validity of the path, use the isValid method. 
555       PathWithStatus(const char *StrStart, unsigned StrLen)
556         : Path(StrStart, StrLen), fsIsValid(false) {}
557     
558       /// This constructor will accept a std::string as a path. No checking is
559       /// done on this path to determine if it is valid. To determine validity
560       /// of the path, use the isValid method. 
561       /// @param p The path to assign.
562       /// @brief Construct a Path from a string.
563       explicit PathWithStatus(const std::string& p) 
564         : Path(p), status(), fsIsValid(false) {}
565
566       /// This constructor will accept a character range as a path.  No checking
567       /// is done on this path to determine if it is valid.  To determine
568       /// validity of the path, use the isValid method. 
569       /// @param p The path to assign.
570       /// @brief Construct a Path from a string.
571       explicit PathWithStatus(const char *StrStart, unsigned StrLen)
572         : Path(StrStart, StrLen), status(), fsIsValid(false) {}
573
574       /// Makes a copy of \p that to \p this.
575       /// @returns \p this
576       /// @brief Assignment Operator
577       PathWithStatus &operator=(const PathWithStatus &that) {
578         static_cast<Path&>(*this) = static_cast<const Path&>(that);
579         status = that.status;
580         fsIsValid = that.fsIsValid;
581         return *this;
582       }
583
584       /// Makes a copy of \p that to \p this.
585       /// @returns \p this
586       /// @brief Assignment Operator
587       PathWithStatus &operator=(const Path &that) {
588         static_cast<Path&>(*this) = static_cast<const Path&>(that);
589         fsIsValid = false;
590         return *this;
591       }
592
593     /// @}
594     /// @name Methods
595     /// @{
596     public:
597       /// This function returns status information about the file. The type of
598       /// path (file or directory) is updated to reflect the actual contents
599       /// of the file system.
600       /// @returns 0 on failure, with Error explaining why (if non-zero)
601       /// @returns a pointer to a FileStatus structure on success.
602       /// @brief Get file status.
603       const FileStatus *getFileStatus(
604         bool forceUpdate = false, ///< Force an update from the file system
605         std::string *Error = 0    ///< Optional place to return an error msg.
606       ) const;
607
608     /// @}
609     /// @name Data
610     /// @{
611     private:
612       mutable FileStatus status; ///< Status information.
613       mutable bool fsIsValid;    ///< Whether we've obtained it or not
614
615     /// @}
616   };
617
618   /// This enumeration delineates the kinds of files that LLVM knows about.
619   enum LLVMFileType {
620     Unknown_FileType = 0,              ///< Unrecognized file
621     Bytecode_FileType,                 ///< Uncompressed bytecode file
622     CompressedBytecode_FileType,       ///< Compressed bytecode file
623     Archive_FileType,                  ///< ar style archive file
624     ELF_Relocatable_FileType,          ///< ELF Relocatable object file
625     ELF_Executable_FileType,           ///< ELF Executable image
626     ELF_SharedObject_FileType,         ///< ELF dynamically linked shared lib
627     ELF_Core_FileType,                 ///< ELF core image
628     Mach_O_Object_FileType,            ///< Mach-O Object file
629     Mach_O_Executable_FileType,        ///< Mach-O Executable
630     Mach_O_FixedVirtualMemorySharedLib_FileType, ///< Mach-O Shared Lib, FVM
631     Mach_O_Core_FileType,              ///< Mach-O Core File
632     Mach_O_PreloadExectuable_FileType, ///< Mach-O Preloaded Executable
633     Mach_O_DynamicallyLinkedSharedLib_FileType, ///< Mach-O dynlinked shared lib
634     Mach_O_DynamicLinker_FileType,     ///< The Mach-O dynamic linker
635     Mach_O_Bundle_FileType,            ///< Mach-O Bundle file
636     Mach_O_DynamicallyLinkedSharedLibStub_FileType, ///< Mach-O Shared lib stub
637     COFF_FileType                      ///< COFF object file or lib
638   };
639
640   /// This utility function allows any memory block to be examined in order
641   /// to determine its file type.
642   LLVMFileType IdentifyFileType(const char*magic, unsigned length);
643
644   /// This function can be used to copy the file specified by Src to the
645   /// file specified by Dest. If an error occurs, Dest is removed.
646   /// @returns true if an error occurs, false otherwise
647   /// @brief Copy one file to another.
648   bool CopyFile(const Path& Dest, const Path& Src, std::string* ErrMsg);
649 }
650
651 std::ostream& operator<<(std::ostream& strm, const sys::Path& aPath);
652 inline std::ostream& operator<<(std::ostream& strm, 
653                                 const sys::PathWithStatus& aPath) {
654   strm << static_cast<const sys::Path&>(aPath);
655   return strm;
656 }
657
658 }
659
660 FORCE_DEFINING_FILE_TO_BE_LINKED(SystemPath)
661 #endif