Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- FileSpec.cpp --------------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Zachary Turner | 5713a05 | 2017-03-22 18:40:07 +0000 | [diff] [blame] | 9 | #include "lldb/Utility/FileSpec.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 10 | #include "lldb/Utility/RegularExpression.h" |
| 11 | #include "lldb/Utility/Stream.h" |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 12 | |
Jonas Devlieghere | ad8d48f | 2018-06-13 16:23:21 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/SmallString.h" |
| 14 | #include "llvm/ADT/SmallVector.h" |
Caroline Tice | 391a960 | 2010-09-12 00:10:52 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/StringRef.h" |
Jonas Devlieghere | ad8d48f | 2018-06-13 16:23:21 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/Triple.h" |
| 17 | #include "llvm/ADT/Twine.h" |
| 18 | #include "llvm/Support/ErrorOr.h" |
Zachary Turner | 3f55974 | 2014-08-07 17:33:36 +0000 | [diff] [blame] | 19 | #include "llvm/Support/FileSystem.h" |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Program.h" |
Jonas Devlieghere | ad8d48f | 2018-06-13 16:23:21 +0000 | [diff] [blame] | 21 | #include "llvm/Support/raw_ostream.h" |
Zachary Turner | 4479ac1 | 2017-04-06 18:12:24 +0000 | [diff] [blame] | 22 | |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 23 | #include <algorithm> |
| 24 | #include <system_error> |
| 25 | #include <vector> |
Zachary Turner | 4479ac1 | 2017-04-06 18:12:24 +0000 | [diff] [blame] | 26 | |
Jonas Devlieghere | 672d2c1 | 2018-11-11 23:16:43 +0000 | [diff] [blame] | 27 | #include <assert.h> |
| 28 | #include <limits.h> |
| 29 | #include <stdio.h> |
| 30 | #include <string.h> |
Caroline Tice | 391a960 | 2010-09-12 00:10:52 +0000 | [diff] [blame] | 31 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | using namespace lldb; |
| 33 | using namespace lldb_private; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | |
Chaoren Lin | 1c614fe | 2015-05-28 17:02:45 +0000 | [diff] [blame] | 35 | namespace { |
| 36 | |
Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 37 | static constexpr FileSpec::Style GetNativeStyle() { |
Nico Weber | b1cb0b79 | 2018-04-10 13:33:45 +0000 | [diff] [blame] | 38 | #if defined(_WIN32) |
Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 39 | return FileSpec::Style::windows; |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 40 | #else |
Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 41 | return FileSpec::Style::posix; |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 42 | #endif |
| 43 | } |
| 44 | |
Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 45 | bool PathStyleIsPosix(FileSpec::Style style) { |
| 46 | return (style == FileSpec::Style::posix || |
| 47 | (style == FileSpec::Style::native && |
| 48 | GetNativeStyle() == FileSpec::Style::posix)); |
Chaoren Lin | 1c614fe | 2015-05-28 17:02:45 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 51 | const char *GetPathSeparators(FileSpec::Style style) { |
Jonas Devlieghere | ad8d48f | 2018-06-13 16:23:21 +0000 | [diff] [blame] | 52 | return llvm::sys::path::get_separator(style).data(); |
Pavel Labath | 144119b | 2016-04-04 14:39:12 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 55 | char GetPreferredPathSeparator(FileSpec::Style style) { |
| 56 | return GetPathSeparators(style)[0]; |
Pavel Labath | 144119b | 2016-04-04 14:39:12 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 59 | void Denormalize(llvm::SmallVectorImpl<char> &path, FileSpec::Style style) { |
| 60 | if (PathStyleIsPosix(style)) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | return; |
Chaoren Lin | 1c614fe | 2015-05-28 17:02:45 +0000 | [diff] [blame] | 62 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | std::replace(path.begin(), path.end(), '/', '\\'); |
Chaoren Lin | 1c614fe | 2015-05-28 17:02:45 +0000 | [diff] [blame] | 64 | } |
Greg Clayton | 86188d8 | 2018-05-21 14:14:36 +0000 | [diff] [blame] | 65 | |
Pavel Labath | 144119b | 2016-04-04 14:39:12 +0000 | [diff] [blame] | 66 | } // end anonymous namespace |
| 67 | |
Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 68 | FileSpec::FileSpec() : m_style(GetNativeStyle()) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 70 | // Default constructor that can take an optional full path to a file on disk. |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 71 | FileSpec::FileSpec(llvm::StringRef path, Style style) : m_style(style) { |
| 72 | SetFile(path, style); |
Jim Ingham | 0909e5f | 2010-09-16 00:57:33 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Jonas Devlieghere | a7d4cec | 2019-08-15 04:35:46 +0000 | [diff] [blame] | 75 | FileSpec::FileSpec(llvm::StringRef path, const llvm::Triple &triple) |
Jonas Devlieghere | 706cd70 | 2019-08-15 05:09:09 +0000 | [diff] [blame] | 76 | : FileSpec{path, triple.isOSWindows() ? Style::windows : Style::posix} {} |
Chaoren Lin | f34f410 | 2015-05-09 01:21:32 +0000 | [diff] [blame] | 77 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | // Copy constructor |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 79 | FileSpec::FileSpec(const FileSpec *rhs) : m_directory(), m_filename() { |
| 80 | if (rhs) |
| 81 | *this = *rhs; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 84 | // Virtual destructor in case anyone inherits from this class. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | FileSpec::~FileSpec() {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 86 | |
Jonas Devlieghere | c1cc317 | 2018-06-25 10:11:53 +0000 | [diff] [blame] | 87 | namespace { |
Jonas Devlieghere | c1cc317 | 2018-06-25 10:11:53 +0000 | [diff] [blame] | 88 | /// Safely get a character at the specified index. |
| 89 | /// |
Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame] | 90 | /// \param[in] path |
Jonas Devlieghere | c1cc317 | 2018-06-25 10:11:53 +0000 | [diff] [blame] | 91 | /// A full, partial, or relative path to a file. |
| 92 | /// |
Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame] | 93 | /// \param[in] i |
Jonas Devlieghere | c1cc317 | 2018-06-25 10:11:53 +0000 | [diff] [blame] | 94 | /// An index into path which may or may not be valid. |
| 95 | /// |
Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame] | 96 | /// \return |
Jonas Devlieghere | c1cc317 | 2018-06-25 10:11:53 +0000 | [diff] [blame] | 97 | /// The character at index \a i if the index is valid, or 0 if |
| 98 | /// the index is not valid. |
Jonas Devlieghere | c1cc317 | 2018-06-25 10:11:53 +0000 | [diff] [blame] | 99 | inline char safeCharAtIndex(const llvm::StringRef &path, size_t i) { |
| 100 | if (i < path.size()) |
| 101 | return path[i]; |
| 102 | return 0; |
| 103 | } |
| 104 | |
Jonas Devlieghere | c1cc317 | 2018-06-25 10:11:53 +0000 | [diff] [blame] | 105 | /// Check if a path needs to be normalized. |
| 106 | /// |
| 107 | /// Check if a path needs to be normalized. We currently consider a |
| 108 | /// path to need normalization if any of the following are true |
| 109 | /// - path contains "/./" |
| 110 | /// - path contains "/../" |
| 111 | /// - path contains "//" |
| 112 | /// - path ends with "/" |
| 113 | /// Paths that start with "./" or with "../" are not considered to |
| 114 | /// need normalization since we aren't trying to resolve the path, |
| 115 | /// we are just trying to remove redundant things from the path. |
| 116 | /// |
Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame] | 117 | /// \param[in] path |
Jonas Devlieghere | c1cc317 | 2018-06-25 10:11:53 +0000 | [diff] [blame] | 118 | /// A full, partial, or relative path to a file. |
| 119 | /// |
Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame] | 120 | /// \return |
Jonas Devlieghere | c1cc317 | 2018-06-25 10:11:53 +0000 | [diff] [blame] | 121 | /// Returns \b true if the path needs to be normalized. |
Jonas Devlieghere | c1cc317 | 2018-06-25 10:11:53 +0000 | [diff] [blame] | 122 | bool needsNormalization(const llvm::StringRef &path) { |
| 123 | if (path.empty()) |
| 124 | return false; |
| 125 | // We strip off leading "." values so these paths need to be normalized |
| 126 | if (path[0] == '.') |
| 127 | return true; |
| 128 | for (auto i = path.find_first_of("\\/"); i != llvm::StringRef::npos; |
| 129 | i = path.find_first_of("\\/", i + 1)) { |
| 130 | const auto next = safeCharAtIndex(path, i+1); |
| 131 | switch (next) { |
| 132 | case 0: |
| 133 | // path separator char at the end of the string which should be |
| 134 | // stripped unless it is the one and only character |
| 135 | return i > 0; |
| 136 | case '/': |
| 137 | case '\\': |
| 138 | // two path separator chars in the middle of a path needs to be |
| 139 | // normalized |
| 140 | if (i > 0) |
| 141 | return true; |
| 142 | ++i; |
| 143 | break; |
| 144 | |
| 145 | case '.': { |
| 146 | const auto next_next = safeCharAtIndex(path, i+2); |
| 147 | switch (next_next) { |
| 148 | default: break; |
| 149 | case 0: return true; // ends with "/." |
| 150 | case '/': |
| 151 | case '\\': |
| 152 | return true; // contains "/./" |
| 153 | case '.': { |
| 154 | const auto next_next_next = safeCharAtIndex(path, i+3); |
| 155 | switch (next_next_next) { |
| 156 | default: break; |
| 157 | case 0: return true; // ends with "/.." |
| 158 | case '/': |
| 159 | case '\\': |
| 160 | return true; // contains "/../" |
| 161 | } |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | break; |
| 167 | |
| 168 | default: |
| 169 | break; |
| 170 | } |
| 171 | } |
| 172 | return false; |
| 173 | } |
| 174 | |
| 175 | |
| 176 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 177 | |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 178 | void FileSpec::SetFile(llvm::StringRef pathname) { SetFile(pathname, m_style); } |
Jonas Devlieghere | 937348c | 2018-06-13 22:08:14 +0000 | [diff] [blame] | 179 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 180 | // Update the contents of this object with a new path. The path will be split |
| 181 | // up into a directory and filename and stored as uniqued string values for |
| 182 | // quick comparison and efficient memory usage. |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 183 | void FileSpec::SetFile(llvm::StringRef pathname, Style style) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 184 | m_filename.Clear(); |
| 185 | m_directory.Clear(); |
| 186 | m_is_resolved = false; |
Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 187 | m_style = (style == Style::native) ? GetNativeStyle() : style; |
Zachary Turner | df62f20 | 2014-08-07 17:33:07 +0000 | [diff] [blame] | 188 | |
Zachary Turner | fe83ad8 | 2016-09-27 20:48:37 +0000 | [diff] [blame] | 189 | if (pathname.empty()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 190 | return; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 191 | |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 192 | llvm::SmallString<128> resolved(pathname); |
Zachary Turner | c7a17ed | 2014-12-01 23:13:32 +0000 | [diff] [blame] | 193 | |
Greg Clayton | 776cd7a | 2018-04-27 15:45:58 +0000 | [diff] [blame] | 194 | // Normalize the path by removing ".", ".." and other redundant components. |
Jonas Devlieghere | c1cc317 | 2018-06-25 10:11:53 +0000 | [diff] [blame] | 195 | if (needsNormalization(resolved)) |
| 196 | llvm::sys::path::remove_dots(resolved, true, m_style); |
Greg Clayton | 776cd7a | 2018-04-27 15:45:58 +0000 | [diff] [blame] | 197 | |
| 198 | // Normalize back slashes to forward slashes |
Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 199 | if (m_style == Style::windows) |
Greg Clayton | 776cd7a | 2018-04-27 15:45:58 +0000 | [diff] [blame] | 200 | std::replace(resolved.begin(), resolved.end(), '\\', '/'); |
Pavel Labath | a212c58 | 2016-04-14 09:38:06 +0000 | [diff] [blame] | 201 | |
Greg Clayton | 39d50b7 | 2018-05-17 16:12:38 +0000 | [diff] [blame] | 202 | if (resolved.empty()) { |
| 203 | // If we have no path after normalization set the path to the current |
| 204 | // directory. This matches what python does and also a few other path |
Jonas Devlieghere | ad8d48f | 2018-06-13 16:23:21 +0000 | [diff] [blame] | 205 | // utilities. |
Greg Clayton | 39d50b7 | 2018-05-17 16:12:38 +0000 | [diff] [blame] | 206 | m_filename.SetString("."); |
| 207 | return; |
| 208 | } |
| 209 | |
Jonas Devlieghere | ad8d48f | 2018-06-13 16:23:21 +0000 | [diff] [blame] | 210 | // Split path into filename and directory. We rely on the underlying char |
| 211 | // pointer to be nullptr when the components are empty. |
| 212 | llvm::StringRef filename = llvm::sys::path::filename(resolved, m_style); |
Jonas Devlieghere | c1cc317 | 2018-06-25 10:11:53 +0000 | [diff] [blame] | 213 | if(!filename.empty()) |
Jonas Devlieghere | ad8d48f | 2018-06-13 16:23:21 +0000 | [diff] [blame] | 214 | m_filename.SetString(filename); |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 215 | |
Jonas Devlieghere | ad8d48f | 2018-06-13 16:23:21 +0000 | [diff] [blame] | 216 | llvm::StringRef directory = llvm::sys::path::parent_path(resolved, m_style); |
Jonas Devlieghere | c1cc317 | 2018-06-25 10:11:53 +0000 | [diff] [blame] | 217 | if(!directory.empty()) |
Jonas Devlieghere | ad8d48f | 2018-06-13 16:23:21 +0000 | [diff] [blame] | 218 | m_directory.SetString(directory); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Jonas Devlieghere | 706cd70 | 2019-08-15 05:09:09 +0000 | [diff] [blame] | 221 | void FileSpec::SetFile(llvm::StringRef path, const llvm::Triple &triple) { |
| 222 | return SetFile(path, triple.isOSWindows() ? Style::windows : Style::posix); |
Chaoren Lin | 44145d7 | 2015-05-29 19:52:37 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 225 | // Convert to pointer operator. This allows code to check any FileSpec objects |
| 226 | // to see if they contain anything valid using code such as: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 227 | // |
| 228 | // if (file_spec) |
| 229 | // {} |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 230 | FileSpec::operator bool() const { return m_filename || m_directory; } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 231 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 232 | // Logical NOT operator. This allows code to check any FileSpec objects to see |
| 233 | // if they are invalid using code such as: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 234 | // |
| 235 | // if (!file_spec) |
| 236 | // {} |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 237 | bool FileSpec::operator!() const { return !m_directory && !m_filename; } |
| 238 | |
| 239 | bool FileSpec::DirectoryEquals(const FileSpec &rhs) const { |
| 240 | const bool case_sensitive = IsCaseSensitive() || rhs.IsCaseSensitive(); |
| 241 | return ConstString::Equals(m_directory, rhs.m_directory, case_sensitive); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 244 | bool FileSpec::FileEquals(const FileSpec &rhs) const { |
| 245 | const bool case_sensitive = IsCaseSensitive() || rhs.IsCaseSensitive(); |
| 246 | return ConstString::Equals(m_filename, rhs.m_filename, case_sensitive); |
Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 249 | // Equal to operator |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 250 | bool FileSpec::operator==(const FileSpec &rhs) const { |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 251 | return FileEquals(rhs) && DirectoryEquals(rhs); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 254 | // Not equal to operator |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 255 | bool FileSpec::operator!=(const FileSpec &rhs) const { return !(*this == rhs); } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 256 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 257 | // Less than operator |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 258 | bool FileSpec::operator<(const FileSpec &rhs) const { |
| 259 | return FileSpec::Compare(*this, rhs, true) < 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 262 | // Dump a FileSpec object to a stream |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 263 | Stream &lldb_private::operator<<(Stream &s, const FileSpec &f) { |
| 264 | f.Dump(&s); |
| 265 | return s; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 268 | // Clear this object by releasing both the directory and filename string values |
| 269 | // and making them both the empty string. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 270 | void FileSpec::Clear() { |
| 271 | m_directory.Clear(); |
| 272 | m_filename.Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 275 | // Compare two FileSpec objects. If "full" is true, then both the directory and |
| 276 | // the filename must match. If "full" is false, then the directory names for |
| 277 | // "a" and "b" are only compared if they are both non-empty. This allows a |
| 278 | // FileSpec object to only contain a filename and it can match FileSpec objects |
| 279 | // that have matching filenames with different paths. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 280 | // |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 281 | // Return -1 if the "a" is less than "b", 0 if "a" is equal to "b" and "1" if |
| 282 | // "a" is greater than "b". |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 283 | int FileSpec::Compare(const FileSpec &a, const FileSpec &b, bool full) { |
| 284 | int result = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 285 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 286 | // case sensitivity of compare |
| 287 | const bool case_sensitive = a.IsCaseSensitive() || b.IsCaseSensitive(); |
Zachary Turner | 47c0346 | 2016-02-24 21:26:47 +0000 | [diff] [blame] | 288 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 289 | // If full is true, then we must compare both the directory and filename. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 290 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 291 | // If full is false, then if either directory is empty, then we match on the |
| 292 | // basename only, and if both directories have valid values, we still do a |
| 293 | // full compare. This allows for matching when we just have a filename in one |
| 294 | // of the FileSpec objects. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 295 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 296 | if (full || (a.m_directory && b.m_directory)) { |
| 297 | result = ConstString::Compare(a.m_directory, b.m_directory, case_sensitive); |
| 298 | if (result) |
| 299 | return result; |
| 300 | } |
| 301 | return ConstString::Compare(a.m_filename, b.m_filename, case_sensitive); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Greg Clayton | 776cd7a | 2018-04-27 15:45:58 +0000 | [diff] [blame] | 304 | bool FileSpec::Equal(const FileSpec &a, const FileSpec &b, bool full) { |
Pavel Labath | b18e190 | 2019-11-28 13:48:05 +0100 | [diff] [blame^] | 305 | if (full || (a.GetDirectory() && b.GetDirectory())) |
| 306 | return a == b; |
Jonas Devlieghere | ad8d48f | 2018-06-13 16:23:21 +0000 | [diff] [blame] | 307 | |
Pavel Labath | b18e190 | 2019-11-28 13:48:05 +0100 | [diff] [blame^] | 308 | return a.FileEquals(b); |
Jim Ingham | 96a1596 | 2014-11-15 01:54:26 +0000 | [diff] [blame] | 309 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 310 | |
Pavel Labath | 841bea9 | 2019-02-11 14:11:00 +0000 | [diff] [blame] | 311 | llvm::Optional<FileSpec::Style> FileSpec::GuessPathStyle(llvm::StringRef absolute_path) { |
| 312 | if (absolute_path.startswith("/")) |
| 313 | return Style::posix; |
| 314 | if (absolute_path.startswith(R"(\\)")) |
| 315 | return Style::windows; |
| 316 | if (absolute_path.size() > 3 && llvm::isAlpha(absolute_path[0]) && |
| 317 | absolute_path.substr(1, 2) == R"(:\)") |
| 318 | return Style::windows; |
| 319 | return llvm::None; |
| 320 | } |
| 321 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 322 | // Dump the object to the supplied stream. If the object contains a valid |
| 323 | // directory name, it will be displayed followed by a directory delimiter, and |
| 324 | // the filename. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 325 | void FileSpec::Dump(Stream *s) const { |
| 326 | if (s) { |
| 327 | std::string path{GetPath(true)}; |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 328 | s->PutCString(path); |
Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 329 | char path_separator = GetPreferredPathSeparator(m_style); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 330 | if (!m_filename && !path.empty() && path.back() != path_separator) |
| 331 | s->PutChar(path_separator); |
| 332 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 335 | FileSpec::Style FileSpec::GetPathStyle() const { return m_style; } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 336 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 337 | // Directory string get accessor. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 338 | ConstString &FileSpec::GetDirectory() { return m_directory; } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 339 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 340 | // Directory string const get accessor. |
Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 341 | ConstString FileSpec::GetDirectory() const { return m_directory; } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 342 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 343 | // Filename string get accessor. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 344 | ConstString &FileSpec::GetFilename() { return m_filename; } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 345 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 346 | // Filename string const get accessor. |
Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 347 | ConstString FileSpec::GetFilename() const { return m_filename; } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 348 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 349 | // Extract the directory and path into a fixed buffer. This is needed as the |
| 350 | // directory and path are stored in separate string values. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 351 | size_t FileSpec::GetPath(char *path, size_t path_max_len, |
| 352 | bool denormalize) const { |
| 353 | if (!path) |
| 354 | return 0; |
Zachary Turner | b6d9924 | 2014-08-08 23:54:35 +0000 | [diff] [blame] | 355 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 356 | std::string result = GetPath(denormalize); |
| 357 | ::snprintf(path, path_max_len, "%s", result.c_str()); |
| 358 | return std::min(path_max_len - 1, result.length()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 361 | std::string FileSpec::GetPath(bool denormalize) const { |
| 362 | llvm::SmallString<64> result; |
| 363 | GetPath(result, denormalize); |
| 364 | return std::string(result.begin(), result.end()); |
Jason Molenda | a7ae467 | 2013-04-29 09:46:43 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 367 | const char *FileSpec::GetCString(bool denormalize) const { |
Jonas Devlieghere | 65e5e278 | 2018-12-13 00:15:17 +0000 | [diff] [blame] | 368 | return ConstString{GetPath(denormalize)}.AsCString(nullptr); |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 371 | void FileSpec::GetPath(llvm::SmallVectorImpl<char> &path, |
| 372 | bool denormalize) const { |
| 373 | path.append(m_directory.GetStringRef().begin(), |
| 374 | m_directory.GetStringRef().end()); |
Greg Clayton | 776cd7a | 2018-04-27 15:45:58 +0000 | [diff] [blame] | 375 | // Since the path was normalized and all paths use '/' when stored in these |
| 376 | // objects, we don't need to look for the actual syntax specific path |
| 377 | // separator, we just look for and insert '/'. |
| 378 | if (m_directory && m_filename && m_directory.GetStringRef().back() != '/' && |
| 379 | m_filename.GetStringRef().back() != '/') |
| 380 | path.insert(path.end(), '/'); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 381 | path.append(m_filename.GetStringRef().begin(), |
| 382 | m_filename.GetStringRef().end()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 383 | if (denormalize && !path.empty()) |
Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 384 | Denormalize(path, m_style); |
Zachary Turner | 4e8ddf5 | 2015-04-09 18:08:50 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 387 | ConstString FileSpec::GetFileNameExtension() const { |
Jonas Devlieghere | 9c1a645 | 2018-06-13 16:36:07 +0000 | [diff] [blame] | 388 | return ConstString( |
| 389 | llvm::sys::path::extension(m_filename.GetStringRef(), m_style)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | ConstString FileSpec::GetFileNameStrippingExtension() const { |
Jonas Devlieghere | 9c1a645 | 2018-06-13 16:36:07 +0000 | [diff] [blame] | 393 | return ConstString(llvm::sys::path::stem(m_filename.GetStringRef(), m_style)); |
Enrico Granata | a9dbf43 | 2011-10-17 21:45:27 +0000 | [diff] [blame] | 394 | } |
| 395 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 396 | // Return the size in bytes that this object takes in memory. This returns the |
| 397 | // size in bytes of this object, not any shared string values it may refer to. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 398 | size_t FileSpec::MemorySize() const { |
| 399 | return m_filename.MemorySize() + m_directory.MemorySize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Zachary Turner | fe83ad8 | 2016-09-27 20:48:37 +0000 | [diff] [blame] | 402 | FileSpec |
| 403 | FileSpec::CopyByAppendingPathComponent(llvm::StringRef component) const { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 404 | FileSpec ret = *this; |
Zachary Turner | fe83ad8 | 2016-09-27 20:48:37 +0000 | [diff] [blame] | 405 | ret.AppendPathComponent(component); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 406 | return ret; |
Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 409 | FileSpec FileSpec::CopyByRemovingLastPathComponent() const { |
Jonas Devlieghere | 24bd63c4 | 2018-06-24 10:18:01 +0000 | [diff] [blame] | 410 | llvm::SmallString<64> current_path; |
| 411 | GetPath(current_path, false); |
| 412 | if (llvm::sys::path::has_parent_path(current_path, m_style)) |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 413 | return FileSpec(llvm::sys::path::parent_path(current_path, m_style), |
Jonas Devlieghere | 24bd63c4 | 2018-06-24 10:18:01 +0000 | [diff] [blame] | 414 | m_style); |
| 415 | return *this; |
Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 418 | ConstString FileSpec::GetLastPathComponent() const { |
Jonas Devlieghere | 24bd63c4 | 2018-06-24 10:18:01 +0000 | [diff] [blame] | 419 | llvm::SmallString<64> current_path; |
| 420 | GetPath(current_path, false); |
| 421 | return ConstString(llvm::sys::path::filename(current_path, m_style)); |
Pavel Labath | 59d725c | 2017-01-16 10:07:02 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Zachary Turner | fe83ad8 | 2016-09-27 20:48:37 +0000 | [diff] [blame] | 424 | void FileSpec::PrependPathComponent(llvm::StringRef component) { |
Jonas Devlieghere | 24bd63c4 | 2018-06-24 10:18:01 +0000 | [diff] [blame] | 425 | llvm::SmallString<64> new_path(component); |
| 426 | llvm::SmallString<64> current_path; |
| 427 | GetPath(current_path, false); |
| 428 | llvm::sys::path::append(new_path, |
| 429 | llvm::sys::path::begin(current_path, m_style), |
| 430 | llvm::sys::path::end(current_path), m_style); |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 431 | SetFile(new_path, m_style); |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 432 | } |
| 433 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 434 | void FileSpec::PrependPathComponent(const FileSpec &new_path) { |
| 435 | return PrependPathComponent(new_path.GetPath(false)); |
Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Zachary Turner | fe83ad8 | 2016-09-27 20:48:37 +0000 | [diff] [blame] | 438 | void FileSpec::AppendPathComponent(llvm::StringRef component) { |
Jonas Devlieghere | 24bd63c4 | 2018-06-24 10:18:01 +0000 | [diff] [blame] | 439 | llvm::SmallString<64> current_path; |
| 440 | GetPath(current_path, false); |
| 441 | llvm::sys::path::append(current_path, m_style, component); |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 442 | SetFile(current_path, m_style); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | void FileSpec::AppendPathComponent(const FileSpec &new_path) { |
| 446 | return AppendPathComponent(new_path.GetPath(false)); |
| 447 | } |
| 448 | |
Jonas Devlieghere | df8e291 | 2018-05-30 13:03:16 +0000 | [diff] [blame] | 449 | bool FileSpec::RemoveLastPathComponent() { |
| 450 | llvm::SmallString<64> current_path; |
| 451 | GetPath(current_path, false); |
| 452 | if (llvm::sys::path::has_parent_path(current_path, m_style)) { |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 453 | SetFile(llvm::sys::path::parent_path(current_path, m_style)); |
Jonas Devlieghere | df8e291 | 2018-05-30 13:03:16 +0000 | [diff] [blame] | 454 | return true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 455 | } |
Jonas Devlieghere | df8e291 | 2018-05-30 13:03:16 +0000 | [diff] [blame] | 456 | return false; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 457 | } |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 458 | /// Returns true if the filespec represents an implementation source |
| 459 | /// file (files with a ".c", ".cpp", ".m", ".mm" (many more) |
| 460 | /// extension). |
| 461 | /// |
Adrian Prantl | f05b42e | 2019-03-11 17:09:29 +0000 | [diff] [blame] | 462 | /// \return |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 463 | /// \b true if the filespec represents an implementation source |
| 464 | /// file, \b false otherwise. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 465 | bool FileSpec::IsSourceImplementationFile() const { |
| 466 | ConstString extension(GetFileNameExtension()); |
Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 467 | if (!extension) |
| 468 | return false; |
| 469 | |
| 470 | static RegularExpression g_source_file_regex(llvm::StringRef( |
Jonas Devlieghere | ad8d48f | 2018-06-13 16:23:21 +0000 | [diff] [blame] | 471 | "^.([cC]|[mM]|[mM][mM]|[cC][pP][pP]|[cC]\\+\\+|[cC][xX][xX]|[cC][cC]|[" |
Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 472 | "cC][pP]|[sS]|[aA][sS][mM]|[fF]|[fF]77|[fF]90|[fF]95|[fF]03|[fF][oO][" |
| 473 | "rR]|[fF][tT][nN]|[fF][pP][pP]|[aA][dD][aA]|[aA][dD][bB]|[aA][dD][sS])" |
| 474 | "$")); |
| 475 | return g_source_file_regex.Execute(extension.GetStringRef()); |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 476 | } |
| 477 | |
Jonas Devlieghere | c1cc317 | 2018-06-25 10:11:53 +0000 | [diff] [blame] | 478 | bool FileSpec::IsRelative() const { |
| 479 | return !IsAbsolute(); |
| 480 | } |
Chaoren Lin | 372e906 | 2015-06-09 17:54:27 +0000 | [diff] [blame] | 481 | |
Jonas Devlieghere | ad8d48f | 2018-06-13 16:23:21 +0000 | [diff] [blame] | 482 | bool FileSpec::IsAbsolute() const { |
| 483 | llvm::SmallString<64> current_path; |
| 484 | GetPath(current_path, false); |
| 485 | |
| 486 | // Early return if the path is empty. |
| 487 | if (current_path.empty()) |
| 488 | return false; |
| 489 | |
| 490 | // We consider paths starting with ~ to be absolute. |
| 491 | if (current_path[0] == '~') |
| 492 | return true; |
| 493 | |
| 494 | return llvm::sys::path::is_absolute(current_path, m_style); |
| 495 | } |
Zachary Turner | 827d5d7 | 2016-12-16 04:27:00 +0000 | [diff] [blame] | 496 | |
Pavel Labath | 7d36d72 | 2019-01-16 12:30:41 +0000 | [diff] [blame] | 497 | void FileSpec::MakeAbsolute(const FileSpec &dir) { |
| 498 | if (IsRelative()) |
| 499 | PrependPathComponent(dir); |
| 500 | } |
| 501 | |
Zachary Turner | 827d5d7 | 2016-12-16 04:27:00 +0000 | [diff] [blame] | 502 | void llvm::format_provider<FileSpec>::format(const FileSpec &F, |
| 503 | raw_ostream &Stream, |
| 504 | StringRef Style) { |
| 505 | assert( |
| 506 | (Style.empty() || Style.equals_lower("F") || Style.equals_lower("D")) && |
| 507 | "Invalid FileSpec style!"); |
| 508 | |
| 509 | StringRef dir = F.GetDirectory().GetStringRef(); |
| 510 | StringRef file = F.GetFilename().GetStringRef(); |
| 511 | |
| 512 | if (dir.empty() && file.empty()) { |
| 513 | Stream << "(empty)"; |
| 514 | return; |
| 515 | } |
| 516 | |
| 517 | if (Style.equals_lower("F")) { |
| 518 | Stream << (file.empty() ? "(empty)" : file); |
| 519 | return; |
| 520 | } |
| 521 | |
| 522 | // Style is either D or empty, either way we need to print the directory. |
| 523 | if (!dir.empty()) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 524 | // Directory is stored in normalized form, which might be different than |
| 525 | // preferred form. In order to handle this, we need to cut off the |
| 526 | // filename, then denormalize, then write the entire denorm'ed directory. |
Zachary Turner | 827d5d7 | 2016-12-16 04:27:00 +0000 | [diff] [blame] | 527 | llvm::SmallString<64> denormalized_dir = dir; |
Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 528 | Denormalize(denormalized_dir, F.GetPathStyle()); |
Zachary Turner | 827d5d7 | 2016-12-16 04:27:00 +0000 | [diff] [blame] | 529 | Stream << denormalized_dir; |
Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 530 | Stream << GetPreferredPathSeparator(F.GetPathStyle()); |
Zachary Turner | 827d5d7 | 2016-12-16 04:27:00 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | if (Style.equals_lower("D")) { |
| 534 | // We only want to print the directory, so now just exit. |
| 535 | if (dir.empty()) |
| 536 | Stream << "(empty)"; |
| 537 | return; |
| 538 | } |
| 539 | |
| 540 | if (!file.empty()) |
| 541 | Stream << file; |
| 542 | } |