Changeset 277219 in webkit
- Timestamp:
- May 7, 2021, 6:05:02 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
-
Source/WTF/ChangeLog (modified) (1 diff)
-
Source/WTF/wtf/FileSystem.cpp (modified) (1 diff)
-
Source/WTF/wtf/glib/FileSystemGlib.cpp (modified) (1 diff)
-
Source/WTF/wtf/posix/FileSystemPOSIX.cpp (modified) (1 diff)
-
Source/WTF/wtf/win/FileSystemWin.cpp (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r277210 r277219 1 2021-05-07 Chris Dumez <cdumez@apple.com> 2 3 Port FileSystem::pathGetFileName() & Filesystem::directoryName() to std::filesystem 4 https://bugs.webkit.org/show_bug.cgi?id=225524 5 6 Reviewed by Darin Adler. 7 8 Port FileSystem::pathGetFileName() & Filesystem::directoryName() to std::filesystem so 9 that we can get rid of platform-specific implementions. 10 11 * wtf/FileSystem.cpp: 12 (WTF::FileSystemImpl::pathGetFileName): 13 (WTF::FileSystemImpl::directoryName): 14 * wtf/glib/FileSystemGlib.cpp: 15 (WTF::FileSystemImpl::pathGetFileName): Deleted. 16 (WTF::FileSystemImpl::directoryName): Deleted. 17 * wtf/posix/FileSystemPOSIX.cpp: 18 (WTF::FileSystemImpl::pathGetFileName): Deleted. 19 (WTF::FileSystemImpl::directoryName): Deleted. 20 * wtf/win/FileSystemWin.cpp: 21 (WTF::FileSystemImpl::pathGetFileName): Deleted. 22 (WTF::FileSystemImpl::directoryName): Deleted. 23 1 24 2021-05-07 Tim Horton <timothy_horton@apple.com> 2 25 -
trunk/Source/WTF/wtf/FileSystem.cpp
r277158 r277219 722 722 } 723 723 724 String pathGetFileName(const String& path) 725 { 726 std::filesystem::path fsPath = fileSystemRepresentation(path).data(); 727 return String::fromUTF8(fsPath.filename().u8string().c_str()); 728 } 729 730 String directoryName(const String& path) 731 { 732 std::filesystem::path fsPath = fileSystemRepresentation(path).data(); 733 return String::fromUTF8(fsPath.parent_path().u8string().c_str()); 734 } 735 724 736 } // namespace FileSystemImpl 725 737 } // namespace WTF -
trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp
r277168 r277219 158 158 } 159 159 160 String pathGetFileName(const String& path)161 {162 auto filename = fileSystemRepresentation(path);163 if (!validRepresentation(filename))164 return path;165 166 GUniquePtr<gchar> baseName(g_path_get_basename(filename.data()));167 return String::fromUTF8(baseName.get());168 }169 170 String directoryName(const String& path)171 {172 auto filename = fileSystemRepresentation(path);173 if (!validRepresentation(filename))174 return String();175 176 GUniquePtr<char> dirname(g_path_get_dirname(filename.data()));177 return String::fromUTF8(dirname.get());178 }179 180 160 Vector<String> listDirectory(const String& path, const String& filter) 181 161 { -
trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp
r277158 r277219 203 203 } 204 204 205 String pathGetFileName(const String& path)206 {207 return path.substring(path.reverseFind('/') + 1);208 }209 210 String directoryName(const String& path)211 {212 CString fsRep = fileSystemRepresentation(path);213 214 if (!fsRep.data() || fsRep.data()[0] == '\0')215 return String();216 217 return String::fromUTF8(dirname(fsRep.mutableData()));218 }219 220 205 Vector<String> listDirectory(const String& path, const String& filter) 221 206 { -
trunk/Source/WTF/wtf/win/FileSystemWin.cpp
r277158 r277219 190 190 } 191 191 192 String pathGetFileName(const String& path)193 {194 return String(::PathFindFileName(path.wideCharacters().data()));195 }196 197 String directoryName(const String& path)198 {199 String name = path.left(path.length() - pathGetFileName(path).length());200 if (name.characterStartingAt(name.length() - 1) == '\\'201 || name.characterStartingAt(name.length() - 1) == '/') {202 // Remove any trailing "\" or "/"203 name.truncate(name.length() - 1);204 }205 return name;206 }207 208 192 static String bundleName() 209 193 { -
trunk/Tools/ChangeLog
r277209 r277219 1 2021-05-07 Chris Dumez <cdumez@apple.com> 2 3 Port FileSystem::pathGetFileName() & Filesystem::directoryName() to std::filesystem 4 https://bugs.webkit.org/show_bug.cgi?id=225524 5 6 Reviewed by Darin Adler. 7 8 Add API test coverage. 9 10 * TestWebKitAPI/Tests/WTF/FileSystem.cpp: 11 (TestWebKitAPI::TEST_F): 12 1 13 2021-05-07 Brent Fulgham <bfulgham@apple.com> 2 14 -
trunk/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp
r277178 r277219 707 707 } 708 708 709 TEST_F(FileSystemTest, pathGetFileName) 710 { 711 auto testPath = FileSystem::pathByAppendingComponents(tempEmptyFolderPath(), { "subfolder", "filename.txt" }); 712 EXPECT_STREQ("filename.txt", FileSystem::pathGetFileName(testPath).utf8().data()); 713 714 #if OS(UNIX) 715 EXPECT_STREQ(".", FileSystem::pathGetFileName(".").utf8().data()); 716 EXPECT_STREQ("..", FileSystem::pathGetFileName("..").utf8().data()); 717 EXPECT_STREQ("", FileSystem::pathGetFileName("/").utf8().data()); 718 EXPECT_STREQ(".", FileSystem::pathGetFileName("/foo/.").utf8().data()); 719 EXPECT_STREQ("..", FileSystem::pathGetFileName("/foo/..").utf8().data()); 720 EXPECT_STREQ("", FileSystem::pathGetFileName("/foo/").utf8().data()); 721 EXPECT_STREQ("host", FileSystem::pathGetFileName("//host").utf8().data()); 722 #endif 723 #if OS(WINDOWS) 724 EXPECT_STREQ("", FileSystem::pathGetFileName("C:\\").utf8().data()); 725 EXPECT_STREQ("foo", FileSystem::pathGetFileName("C:\\foo").utf8().data()); 726 EXPECT_STREQ("", FileSystem::pathGetFileName("C:\\foo\\").utf8().data()); 727 EXPECT_STREQ("bar.txt", FileSystem::pathGetFileName("C:\\foo\\bar.txt").utf8().data()); 728 #endif 729 } 730 731 TEST_F(FileSystemTest, directoryName) 732 { 733 auto testPath = FileSystem::pathByAppendingComponents(tempEmptyFolderPath(), { "subfolder", "filename.txt" }); 734 EXPECT_STREQ(FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), "subfolder").utf8().data(), FileSystem::directoryName(testPath).utf8().data()); 735 #if OS(UNIX) 736 EXPECT_STREQ("/var/tmp", FileSystem::directoryName("/var/tmp/example.txt").utf8().data()); 737 EXPECT_STREQ("/var/tmp", FileSystem::directoryName("/var/tmp/").utf8().data()); 738 EXPECT_STREQ("/var/tmp", FileSystem::directoryName("/var/tmp/.").utf8().data()); 739 EXPECT_STREQ("/", FileSystem::directoryName("/").utf8().data()); 740 #endif 741 #if OS(WINDOWS) 742 EXPECT_STREQ("C:\\foo", FileSystem::directoryName("C:\\foo\\example.txt").utf8().data()); 743 EXPECT_STREQ("C:\\", FileSystem::directoryName("C:\\").utf8().data()); 744 #endif 745 } 746 709 747 } // namespace TestWebKitAPI
Note:
See TracChangeset
for help on using the changeset viewer.