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

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: . 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
« base/file_util_posix.cc ('K') | « 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..4266ae282ff71a898d6493dd8c65bccb59b8ca1b 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -744,6 +744,55 @@ TEST_F(FileUtilTest, DeleteFile) {
EXPECT_FALSE(file_util::PathExists(file_name));
}
+#if defined(OS_POSIX)
+TEST_F(FileUtilTest, DeleteSymlinkOfExistentFile) {
satorux1 2012/06/29 18:25:20 DeleteSymlinkToExistentFile
yoshiki 2012/06/29 19:12:27 Done.
+ // 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, DeleteSymlinkOfNonExistentFile) {
satorux1 2012/06/29 18:25:20 DeleteSymlinkToNonExistentFile
satorux1 2012/06/29 18:25:20 DeleteSymlinkToNonExistentFile
yoshiki 2012/06/29 19:12:27 Done.
+ // Create a dummy file to be deleted.
+ FilePath non_existent = temp_dir_.path().Append(FPL("Test DeleteFile 3.txt"));
+ CreateTextFile(non_existent, bogus_content);
+ EXPECT_TRUE(file_util::PathExists(non_existent));
satorux1 2012/06/29 18:25:20 You don't need a dummy file to create a dangling s
yoshiki 2012/06/29 19:12:27 Done.
+
+ // Create a symlink to the dummy file.
+ FilePath file_link = temp_dir_.path().Append("file_link_3");
+ ASSERT_TRUE(file_util::CreateSymbolicLink(non_existent, file_link))
+ << "Failed to create symlink.";
+ EXPECT_TRUE(file_util::PathExists(non_existent));
+ EXPECT_TRUE(file_util::PathExists(file_link));
+
+ // Delete the dummy file, keeping the symbolic link.
+ EXPECT_TRUE(file_util::Delete(non_existent, false));
+ EXPECT_FALSE(file_util::PathExists(non_existent));
+ EXPECT_FALSE(file_util::PathExists(file_link));
satorux1 2012/06/29 18:25:20 I'd suggest to remove this part too.
yoshiki 2012/06/29 19:12:27 Done.
+
+ // Make sure the symbolic link is not deleted
+ EXPECT_TRUE(file_util::IsLink(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.
« base/file_util_posix.cc ('K') | « base/file_util_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698