llvm.org GIT mirror llvm / 7ae606a
Revert r146363 to allow buildbots to make forward progress. Original commit message: Support/FileSystem: Implement canonicalize. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146378 91177308-0d34-0410-b5e6-96231b3b80d8 Chad Rosier 8 years ago
5 changed file(s) with 2 addition(s) and 99 deletion(s). Raw diff Collapse all Expand all
388388
389389 /// @brief Canonicalize path.
390390 ///
391 /// Sets result to the file system's idea of what path is. Path must be
392 /// absolute. The result has the same case as the file system.
393 ///
394 /// Example: Give a file system with "C:\a\b\c\file.txt".
395 ///
396 /// C:\A\b\C\fIlE.TxT => C:\a\b\c\file.txt
391 /// Sets result to the file system's idea of what path is. The result is always
392 /// absolute and has the same capitalization as the file system.
397393 ///
398394 /// @param path Input path.
399395 /// @param result Set to the canonicalized version of \a path.
430430 return success;
431431 }
432432
433 error_code canonicalize(const Twine &path, SmallVectorImpl &result) {
434 // Paths are already canonicalized on posix systems.
435 assert(path::is_absolute(path) && "path must be absolute!");
436 path.toVector(result);
437 return success;
438 }
439
440433 error_code detail::directory_iterator_construct(detail::DirIterState &it,
441434 StringRef path){
442435 SmallString<128> path_null(path);
613613 return success;
614614 }
615615
616 error_code canonicalize(const Twine &path, SmallVectorImpl &result) {
617 assert(path::is_absolute(path) && "path must be absolute!");
618 SmallString<128> path_storage;
619 StringRef p = path.toStringRef(path_storage);
620 SmallVector path_utf16;
621 result.set_size(0);
622
623 // Convert path to UTF-16.
624 if (error_code ec = UTF8ToUTF16(p, path_utf16))
625 return ec;
626
627 DWORD size = ::GetShortPathNameW(c_str(path_utf16), NULL, 0);
628 SmallVector short_path;
629 short_path.reserve(size + 1);
630 size = ::GetShortPathNameW( c_str(path_utf16)
631 , short_path.data()
632 , short_path.capacity());
633 if (!size)
634 return windows_error(::GetLastError());
635
636 short_path.set_size(size);
637
638 size = ::GetLongPathNameW(c_str(short_path), NULL, 0);
639 path_utf16.reserve(size + 1);
640 size = ::GetLongPathNameW( c_str(short_path)
641 , path_utf16.data()
642 , path_utf16.capacity());
643 if (!size)
644 return windows_error(::GetLastError());
645
646 path_utf16.set_size(size);
647
648 if (error_code ec = UTF16ToUTF8(path_utf16.data(), path_utf16.size(), result))
649 return ec;
650
651 return success;
652 }
653
654616 error_code get_magic(const Twine &path, uint32_t len,
655617 SmallVectorImpl &result) {
656618 SmallString<128> path_storage;
127127 }
128128 };
129129
130 struct FileMappingHandleTraits : CommonHandleTraits {
131 static handle_type GetInvalid() {
132 return 0;
133 }
134 };
135
136 struct MappedViewOfFileHandleTraits : CommonHandleTraits {
137 typedef LPVOID handle_type;
138
139 static handle_type GetInvalid() {
140 return 0;
141 }
142
143 static void Close(handle_type h) {
144 ::UnmapViewOfFile(h);
145 }
146 };
147
148130 struct FileHandleTraits : CommonHandleTraits {};
149131
150132 typedef ScopedHandle ScopedCommonHandle;
152134 typedef ScopedHandle ScopedCryptContext;
153135 typedef ScopedHandle ScopedFindHandle;
154136 typedef ScopedHandle ScopedJobHandle;
155 typedef ScopedHandle ScopedFileMappingHandle;
156 typedef ScopedHandle ScopedMappedViewOfFileHandle;
157137
158138 namespace llvm {
159139 template
311311 }
312312 }
313313
314 TEST_F(FileSystemTest, Canonicalize) {
315 SmallString<128> file_pathname(TestDirectory);
316 path::append(file_pathname, "canonicalize", "a0", "aa1");
317
318 bool existed;
319 ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory)
320 + "/canonicalize/a0/aa1", existed));
321
322 {
323 path::append(file_pathname, "file.txt");
324 std::string ErrMsg;
325 raw_fd_ostream file(file_pathname.c_str(), ErrMsg);
326 file << "hello\n";
327 }
328
329 SmallString<0> res;
330 ASSERT_NO_ERROR(fs::canonicalize(Twine(TestDirectory)
331 + "/cAnOnIcAlIzE/A0/aA1/fIlE.TxT", res));
332 // Only check if we actually found the file. As we won't find it on case
333 // sensitive file systems.
334 if (fs::exists(res.str())) {
335 ASSERT_TRUE(res.str().find("canonicalize") != StringRef::npos);
336 ASSERT_TRUE(res.str().find("a0") != StringRef::npos);
337 ASSERT_TRUE(res.str().find("aa1") != StringRef::npos);
338 ASSERT_TRUE(res.str().find("file.txt") != StringRef::npos);
339 }
340 }
341
342314 } // anonymous namespace