Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3848)

Unified Diff: base/file_util_unittest.cc

Issue 10690047: Fix a bug in file_util::Delete() where symlinks are not handled right (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync & add comment Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/file_util_posix.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_unittest.cc
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index ea8918bbc89e69d6c6597125ac19a8ee956766fa..55f2039e4519d23183898a8b7bda990f1860ba6a 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -744,6 +744,48 @@ TEST_F(FileUtilTest, DeleteFile) {
EXPECT_FALSE(file_util::PathExists(file_name));
}
+#if defined(OS_POSIX)
+TEST_F(FileUtilTest, DeleteSymlinkToExistentFile) {
+ // Create a file
+ FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt"));
+ CreateTextFile(file_name, bogus_content);
+ ASSERT_TRUE(file_util::PathExists(file_name));
+
+ // Create a symlink to the file
+ FilePath file_link = temp_dir_.path().Append("file_link_2");
+ ASSERT_TRUE(file_util::CreateSymbolicLink(file_name, file_link))
+ << "Failed to create symlink.";
+
+ // Delete the symbolic link
+ EXPECT_TRUE(file_util::Delete(file_link, false));
+
+ // Make sure original file is not deleted
+ EXPECT_FALSE(file_util::PathExists(file_link));
+ EXPECT_TRUE(file_util::PathExists(file_name));
+}
+
+TEST_F(FileUtilTest, DeleteSymlinkToNonExistentFile) {
+ // Create a non-existent file path
+ FilePath non_existent = temp_dir_.path().Append(FPL("Test DeleteFile 3.txt"));
+ EXPECT_FALSE(file_util::PathExists(non_existent));
+
+ // Create a symlink to the non-existent file
+ FilePath file_link = temp_dir_.path().Append("file_link_3");
+ ASSERT_TRUE(file_util::CreateSymbolicLink(non_existent, file_link))
+ << "Failed to create symlink.";
+
+ // Make sure the symbolic link is exist
+ EXPECT_TRUE(file_util::IsLink(file_link));
+ EXPECT_FALSE(file_util::PathExists(file_link));
+
+ // Delete the symbolic link
+ EXPECT_TRUE(file_util::Delete(file_link, false));
+
+ // Make sure the symbolic link is deleted
+ EXPECT_FALSE(file_util::IsLink(file_link));
+}
+#endif // defined(OS_POSIX)
+
#if defined(OS_WIN)
// Tests that the Delete function works for wild cards, especially
// with the recursion flag. Also coincidentally tests PathExists.
« no previous file with comments | « base/file_util_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698