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

Side by Side 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, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_util_posix.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 // Test recursive case, create a new file 737 // Test recursive case, create a new file
738 file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); 738 file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt"));
739 CreateTextFile(file_name, bogus_content); 739 CreateTextFile(file_name, bogus_content);
740 ASSERT_TRUE(file_util::PathExists(file_name)); 740 ASSERT_TRUE(file_util::PathExists(file_name));
741 741
742 // Make sure it's deleted 742 // Make sure it's deleted
743 EXPECT_TRUE(file_util::Delete(file_name, true)); 743 EXPECT_TRUE(file_util::Delete(file_name, true));
744 EXPECT_FALSE(file_util::PathExists(file_name)); 744 EXPECT_FALSE(file_util::PathExists(file_name));
745 } 745 }
746 746
747 #if defined(OS_POSIX)
748 TEST_F(FileUtilTest, DeleteSymlinkToExistentFile) {
749 // Create a file
750 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt"));
751 CreateTextFile(file_name, bogus_content);
752 ASSERT_TRUE(file_util::PathExists(file_name));
753
754 // Create a symlink to the file
755 FilePath file_link = temp_dir_.path().Append("file_link_2");
756 ASSERT_TRUE(file_util::CreateSymbolicLink(file_name, file_link))
757 << "Failed to create symlink.";
758
759 // Delete the symbolic link
760 EXPECT_TRUE(file_util::Delete(file_link, false));
761
762 // Make sure original file is not deleted
763 EXPECT_FALSE(file_util::PathExists(file_link));
764 EXPECT_TRUE(file_util::PathExists(file_name));
765 }
766
767 TEST_F(FileUtilTest, DeleteSymlinkToNonExistentFile) {
768 // Create a non-existent file path
769 FilePath non_existent = temp_dir_.path().Append(FPL("Test DeleteFile 3.txt"));
770 EXPECT_FALSE(file_util::PathExists(non_existent));
771
772 // Create a symlink to the non-existent file
773 FilePath file_link = temp_dir_.path().Append("file_link_3");
774 ASSERT_TRUE(file_util::CreateSymbolicLink(non_existent, file_link))
775 << "Failed to create symlink.";
776
777 // Make sure the symbolic link is exist
778 EXPECT_TRUE(file_util::IsLink(file_link));
779 EXPECT_FALSE(file_util::PathExists(file_link));
780
781 // Delete the symbolic link
782 EXPECT_TRUE(file_util::Delete(file_link, false));
783
784 // Make sure the symbolic link is deleted
785 EXPECT_FALSE(file_util::IsLink(file_link));
786 }
787 #endif // defined(OS_POSIX)
788
747 #if defined(OS_WIN) 789 #if defined(OS_WIN)
748 // Tests that the Delete function works for wild cards, especially 790 // Tests that the Delete function works for wild cards, especially
749 // with the recursion flag. Also coincidentally tests PathExists. 791 // with the recursion flag. Also coincidentally tests PathExists.
750 // TODO(erikkay): see if anyone's actually using this feature of the API 792 // TODO(erikkay): see if anyone's actually using this feature of the API
751 TEST_F(FileUtilTest, DeleteWildCard) { 793 TEST_F(FileUtilTest, DeleteWildCard) {
752 // Create a file and a directory 794 // Create a file and a directory
753 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt")); 795 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt"));
754 CreateTextFile(file_name, bogus_content); 796 CreateTextFile(file_name, bogus_content);
755 ASSERT_TRUE(file_util::PathExists(file_name)); 797 ASSERT_TRUE(file_util::PathExists(file_name));
756 798
(...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after
2276 file_util::VerifyPathControlledByUser( 2318 file_util::VerifyPathControlledByUser(
2277 base_dir_, text_file_, uid_, ok_gids_)); 2319 base_dir_, text_file_, uid_, ok_gids_));
2278 EXPECT_TRUE( 2320 EXPECT_TRUE(
2279 file_util::VerifyPathControlledByUser( 2321 file_util::VerifyPathControlledByUser(
2280 sub_dir_, text_file_, uid_, ok_gids_)); 2322 sub_dir_, text_file_, uid_, ok_gids_));
2281 } 2323 }
2282 2324
2283 #endif // defined(OS_POSIX) 2325 #endif // defined(OS_POSIX)
2284 2326
2285 } // namespace 2327 } // namespace
OLDNEW
« 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