Changeset 277446 in webkit
- Timestamp:
- May 13, 2021, 12:43:37 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/FileSystem.h (modified) (1 diff)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/NetworkProcess/cache/NetworkCacheBlobStorage.cpp (modified) (2 diffs)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r277438 r277446 1 2021-05-13 Chris Dumez <cdumez@apple.com> 2 3 Introduce FileSystem::hardLinkCount() 4 https://bugs.webkit.org/show_bug.cgi?id=225767 5 6 Reviewed by Darin Adler. 7 8 Introduce FileSystem::hardLinkCount() to replace our platform-specific implementation 9 in NetworkCacheBlobStorage. 10 11 * wtf/FileSystem.cpp: 12 (WTF::FileSystemImpl::hardLinkCount): 13 * wtf/FileSystem.h: 14 1 15 2021-05-13 Alicia Boya García <aboya@igalia.com> 2 16 -
trunk/Source/WTF/wtf/FileSystem.cpp
r277357 r277446 664 664 } 665 665 666 Optional<uint64_t> hardLinkCount(const String& path) 667 { 668 std::error_code ec; 669 uint64_t linkCount = std::filesystem::hard_link_count(toStdFileSystemPath(path), ec); 670 return ec ? WTF::nullopt : makeOptional(linkCount); 671 } 672 666 673 bool deleteNonEmptyDirectory(const String& path) 667 674 { -
trunk/Source/WTF/wtf/FileSystem.h
r277357 r277446 170 170 // Hard links a file if possible, copies it if not. 171 171 WTF_EXPORT_PRIVATE bool hardLinkOrCopyFile(const String& targetPath, const String& linkPath); 172 WTF_EXPORT_PRIVATE Optional<uint64_t> hardLinkCount(const String& path); 172 173 173 174 #if USE(FILE_LOCK) -
trunk/Source/WebKit/ChangeLog
r277439 r277446 1 2021-05-13 Chris Dumez <cdumez@apple.com> 2 3 Introduce FileSystem::hardLinkCount() 4 https://bugs.webkit.org/show_bug.cgi?id=225767 5 6 Reviewed by Darin Adler. 7 8 Leverage the FileSystem API instead of having platform-specific code. 9 10 * NetworkProcess/cache/NetworkCacheBlobStorage.cpp: 11 (WebKit::NetworkCache::BlobStorage::synchronize): 12 (WebKit::NetworkCache::BlobStorage::shareCount): 13 1 14 2021-05-13 Sam Weinig <weinig@apple.com> 2 15 -
trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheBlobStorage.cpp
r254703 r277446 66 66 return; 67 67 auto path = FileSystem::pathByAppendingComponent(blobDirectory, name); 68 auto filePath = FileSystem::fileSystemRepresentation(path); 69 struct stat stat; 70 ::stat(filePath.data(), &stat); 68 auto linkCount = FileSystem::hardLinkCount(path); 71 69 // No clients left for this blob. 72 if (stat.st_nlink == 1) 73 unlink(filePath.data()); 74 else 75 m_approximateSize += stat.st_size; 70 if (linkCount && *linkCount == 1) 71 FileSystem::deleteFile(path); 72 else { 73 long long fileSize = 0; 74 FileSystem::getFileSize(path, fileSize); 75 m_approximateSize += fileSize; 76 } 76 77 }); 77 78 … … 142 143 ASSERT(!RunLoop::isMain()); 143 144 144 auto linkPath = FileSystem::fileSystemRepresentation(path); 145 struct stat stat; 146 if (::stat(linkPath.data(), &stat) < 0) 145 auto linkCount = FileSystem::hardLinkCount(path); 146 if (!linkCount) 147 147 return 0; 148 148 // Link count is 2 in the single client case (the blob file and a link). 149 return stat.st_nlink- 1;149 return *linkCount - 1; 150 150 } 151 151 -
trunk/Tools/ChangeLog
r277444 r277446 1 2021-05-13 Chris Dumez <cdumez@apple.com> 2 3 Introduce FileSystem::hardLinkCount() 4 https://bugs.webkit.org/show_bug.cgi?id=225767 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-13 Jonathan Bedard <jbedard@apple.com> 2 14 -
trunk/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp
r277357 r277446 660 660 } 661 661 662 TEST_F(FileSystemTest, hardLinkCount) 663 { 664 auto linkCount = FileSystem::hardLinkCount(tempFilePath()); 665 ASSERT_TRUE(!!linkCount); 666 EXPECT_EQ(*linkCount, 1U); 667 668 auto hardlink1Path = FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), "tempFile-hardlink1"); 669 EXPECT_TRUE(FileSystem::hardLink(tempFilePath(), hardlink1Path)); 670 linkCount = FileSystem::hardLinkCount(tempFilePath()); 671 ASSERT_TRUE(!!linkCount); 672 EXPECT_EQ(*linkCount, 2U); 673 674 auto hardlink2Path = FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), "tempFile-hardlink2"); 675 EXPECT_TRUE(FileSystem::hardLink(tempFilePath(), hardlink2Path)); 676 linkCount = FileSystem::hardLinkCount(tempFilePath()); 677 ASSERT_TRUE(!!linkCount); 678 EXPECT_EQ(*linkCount, 3U); 679 680 EXPECT_TRUE(FileSystem::deleteFile(hardlink1Path)); 681 linkCount = FileSystem::hardLinkCount(tempFilePath()); 682 ASSERT_TRUE(!!linkCount); 683 EXPECT_EQ(*linkCount, 2U); 684 685 EXPECT_TRUE(FileSystem::deleteFile(hardlink2Path)); 686 linkCount = FileSystem::hardLinkCount(tempFilePath()); 687 ASSERT_TRUE(!!linkCount); 688 EXPECT_EQ(*linkCount, 1U); 689 690 EXPECT_TRUE(FileSystem::deleteFile(tempFilePath())); 691 linkCount = FileSystem::hardLinkCount(tempFilePath()); 692 EXPECT_TRUE(!linkCount); 693 } 694 662 695 static void runGetFileModificationTimeTest(const String& path, Function<Optional<WallTime>(const String&)>&& getFileModificationTime) 663 696 {
Note:
See TracChangeset
for help on using the changeset viewer.