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

Side by Side Diff: components/drive/file_cache.cc

Issue 1815053003: Revert of Reland: Create hard links in file migration if necessary. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « components/drive/file_cache.h ('k') | components/drive/file_cache_unittest.cc » ('j') | 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 "components/drive/file_cache.h" 5 #include "components/drive/file_cache.h"
6 6
7 #include <unistd.h>
8
9 #include <queue> 7 #include <queue>
10 #include <vector> 8 #include <vector>
11 9
12 #include "base/bind.h" 10 #include "base/bind.h"
13 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
14 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
15 #include "base/files/file_enumerator.h" 13 #include "base/files/file_enumerator.h"
16 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
17 #include "base/location.h" 15 #include "base/location.h"
18 #include "base/logging.h" 16 #include "base/logging.h"
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 const std::string& id = GetIdFromPath(new_path); 674 const std::string& id = GetIdFromPath(new_path);
677 new_path = GetCacheFilePath(util::CanonicalizeResourceId(id)); 675 new_path = GetCacheFilePath(util::CanonicalizeResourceId(id));
678 if (new_path != current && !base::Move(current, new_path)) 676 if (new_path != current && !base::Move(current, new_path))
679 return false; 677 return false;
680 } 678 }
681 return true; 679 return true;
682 } 680 }
683 681
684 // static 682 // static
685 bool FileCache::MigrateCacheFiles(const base::FilePath& from, 683 bool FileCache::MigrateCacheFiles(const base::FilePath& from,
686 const base::FilePath& to_files, 684 const base::FilePath& to,
687 const base::FilePath& to_links,
688 ResourceMetadataStorage* metadata_storage) { 685 ResourceMetadataStorage* metadata_storage) {
689 scoped_ptr<ResourceMetadataStorage::Iterator> it = 686 scoped_ptr<ResourceMetadataStorage::Iterator> it =
690 metadata_storage->GetIterator(); 687 metadata_storage->GetIterator();
691 for (; !it->IsAtEnd(); it->Advance()) { 688 for (; !it->IsAtEnd(); it->Advance()) {
692 const ResourceEntry& entry = it->GetValue(); 689 const ResourceEntry& entry = it->GetValue();
693 if (!entry.file_specific_info().cache_state().is_present()) { 690 if (!entry.file_specific_info().cache_state().is_present()) {
694 continue; 691 continue;
695 } 692 }
696 693
697 // Ignore missing cache file case since it never succeeds.
698 // TODO(yawano): handle this case at metadata validation in FileCache.
699 const base::FilePath move_from = GetPathForId(from, entry.local_id()); 694 const base::FilePath move_from = GetPathForId(from, entry.local_id());
700 if (!base::PathExists(move_from)) { 695 if (!base::PathExists(move_from)) {
701 continue; 696 continue;
702 } 697 }
703 698
704 // Create hard link to cache file if it's pinned or dirty. cryptohome will 699 const base::FilePath move_to = GetPathForId(to, entry.local_id());
705 // not delete a cache file if there is a hard link to it.
706 const FileCacheEntry& file_cache_entry =
707 entry.file_specific_info().cache_state();
708 if (file_cache_entry.is_pinned() || file_cache_entry.is_dirty()) {
709 const base::FilePath link_path = GetPathForId(to_links, entry.local_id());
710 int link_result = link(move_from.AsUTF8Unsafe().c_str(),
711 link_path.AsUTF8Unsafe().c_str());
712 if (link_result != 0 && errno != EEXIST) {
713 return false;
714 }
715 }
716
717 // Move cache file.
718 const base::FilePath move_to = GetPathForId(to_files, entry.local_id());
719 if (!base::Move(move_from, move_to)) { 700 if (!base::Move(move_from, move_to)) {
720 return false; 701 return false;
721 } 702 }
703
704 // TODO(yawano): create hard link if entry is marked as pinned or dirty.
722 } 705 }
723 706
724 return true; 707 return true;
725 } 708 }
726 709
727 void FileCache::CloseForWrite(const std::string& id) { 710 void FileCache::CloseForWrite(const std::string& id) {
728 AssertOnSequencedWorkerPool(); 711 AssertOnSequencedWorkerPool();
729 712
730 std::map<std::string, int>::iterator it = write_opened_files_.find(id); 713 std::map<std::string, int>::iterator it = write_opened_files_.find(id);
731 if (it == write_opened_files_.end()) 714 if (it == write_opened_files_.end())
(...skipping 23 matching lines...) Expand all
755 738
756 bool FileCache::IsEvictable(const std::string& id, const ResourceEntry& entry) { 739 bool FileCache::IsEvictable(const std::string& id, const ResourceEntry& entry) {
757 return entry.file_specific_info().has_cache_state() && 740 return entry.file_specific_info().has_cache_state() &&
758 !entry.file_specific_info().cache_state().is_pinned() && 741 !entry.file_specific_info().cache_state().is_pinned() &&
759 !entry.file_specific_info().cache_state().is_dirty() && 742 !entry.file_specific_info().cache_state().is_dirty() &&
760 !mounted_files_.count(id); 743 !mounted_files_.count(id);
761 } 744 }
762 745
763 } // namespace internal 746 } // namespace internal
764 } // namespace drive 747 } // namespace drive
OLDNEW
« no previous file with comments | « components/drive/file_cache.h ('k') | components/drive/file_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698