summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkeishi@chromium.org <keishi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-08 07:10:03 +0000
committerkeishi@chromium.org <keishi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-08 07:10:03 +0000
commit7e9f057cb7830df212b60fd438dfce15e8cec3fb (patch)
tree33dce3466197a30c98c7a0ad127f327e0660fce6
parentb16c5d87d5cb06f5e1d40f845fb805daba24f8f7 (diff)
downloadchromium_src-7e9f057cb7830df212b60fd438dfce15e8cec3fb.zip
chromium_src-7e9f057cb7830df212b60fd438dfce15e8cec3fb.tar.gz
chromium_src-7e9f057cb7830df212b60fd438dfce15e8cec3fb.tar.bz2
Check for NOT_A_DIRECTORY error in remote to local syncer
TEST=Automated. Added RemoteToLocalSyncerTest.Conflict_CreateNestedFolderOnFile BUG=240165 Review URL: https://codereview.chromium.org/104503002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239386 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.cc2
-rw-r--r--chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer_unittest.cc36
-rw-r--r--chrome/browser/sync_file_system/fake_remote_change_processor.cc33
3 files changed, 69 insertions, 2 deletions
diff --git a/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.cc b/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.cc
index 0a6d4f2..8baa3f3 100644
--- a/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.cc
+++ b/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.cc
@@ -668,6 +668,8 @@ void RemoteToLocalSyncer::DidCalculateMD5ForDownload(
void RemoteToLocalSyncer::DidApplyDownload(const SyncStatusCallback& callback,
webkit_blob::ScopedFile,
SyncStatusCode status) {
+ if (status != SYNC_STATUS_OK)
+ metadata_database()->LowerTrackerPriority(dirty_tracker_->tracker_id());
callback.Run(status);
}
diff --git a/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer_unittest.cc b/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer_unittest.cc
index 2c45624..85faf15 100644
--- a/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer_unittest.cc
+++ b/chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer_unittest.cc
@@ -462,5 +462,41 @@ TEST_F(RemoteToLocalSyncerTest, Conflict_CreateFileOnFile) {
EXPECT_TRUE(GetMetadataDatabase()->GetLowPriorityDirtyTracker(NULL));
}
+TEST_F(RemoteToLocalSyncerTest, Conflict_CreateNestedFolderOnFile) {
+ const GURL kOrigin("chrome-extension://example");
+ const std::string sync_root = CreateSyncRoot();
+ const std::string app_root = CreateRemoteFolder(sync_root, kOrigin.host());
+ InitializeMetadataDatabase();
+ RegisterApp(kOrigin.host(), app_root);
+
+ AppendExpectedChange(URL(kOrigin, "/"),
+ FileChange::FILE_CHANGE_ADD_OR_UPDATE,
+ SYNC_FILE_TYPE_DIRECTORY);
+
+ RunSyncerUntilIdle();
+ VerifyConsistency();
+
+ const std::string folder = CreateRemoteFolder(app_root, "folder");
+
+ AppendExpectedChange(URL(kOrigin, "/folder"),
+ FileChange::FILE_CHANGE_ADD_OR_UPDATE,
+ SYNC_FILE_TYPE_DIRECTORY);
+
+ ListChanges();
+ RunSyncerUntilIdle();
+
+ CreateLocalFile(URL(kOrigin, "/folder"));
+ CreateRemoteFile(folder, "file", "data");
+
+ // File-Folder conflict happens. Folder should override the existing file.
+ AppendExpectedChange(URL(kOrigin, "/folder"),
+ FileChange::FILE_CHANGE_ADD_OR_UPDATE,
+ SYNC_FILE_TYPE_DIRECTORY);
+
+ ListChanges();
+ RunSyncerUntilIdle();
+ VerifyConsistency();
+}
+
} // namespace drive_backend
} // namespace sync_file_system
diff --git a/chrome/browser/sync_file_system/fake_remote_change_processor.cc b/chrome/browser/sync_file_system/fake_remote_change_processor.cc
index 03fdb64..c92f8db 100644
--- a/chrome/browser/sync_file_system/fake_remote_change_processor.cc
+++ b/chrome/browser/sync_file_system/fake_remote_change_processor.cc
@@ -10,7 +10,9 @@
#include "base/message_loop/message_loop_proxy.h"
#include "chrome/browser/sync_file_system/file_change.h"
#include "chrome/browser/sync_file_system/sync_file_metadata.h"
+#include "chrome/browser/sync_file_system/syncable_file_system_util.h"
#include "webkit/browser/fileapi/file_system_url.h"
+#include "webkit/common/fileapi/file_system_util.h"
namespace sync_file_system {
@@ -58,9 +60,36 @@ void FakeRemoteChangeProcessor::ApplyRemoteChange(
const base::FilePath& local_path,
const fileapi::FileSystemURL& url,
const SyncStatusCallback& callback) {
- applied_changes_[url].push_back(change);
+ SyncStatusCode status = SYNC_STATUS_UNKNOWN;
+ base::FilePath ancestor = fileapi::VirtualPath::DirName(url.path());
+ while (true) {
+ fileapi::FileSystemURL ancestor_url =
+ CreateSyncableFileSystemURL(url.origin(), ancestor);
+ if (!ancestor_url.is_valid())
+ break;
+
+ URLToFileChangeList::iterator found_list =
+ local_changes_.find(ancestor_url);
+ if (found_list != local_changes_.end()) {
+ const FileChange& local_change = found_list->second.back();
+ if (local_change.IsAddOrUpdate() &&
+ local_change.file_type() != SYNC_FILE_TYPE_DIRECTORY) {
+ status = SYNC_FILE_ERROR_NOT_A_DIRECTORY;
+ break;
+ }
+ }
+
+ base::FilePath ancestor_parent = fileapi::VirtualPath::DirName(ancestor);
+ if (ancestor == ancestor_parent)
+ break;
+ ancestor = ancestor_parent;
+ }
+ if (status == SYNC_STATUS_UNKNOWN) {
+ applied_changes_[url].push_back(change);
+ status = SYNC_STATUS_OK;
+ }
base::MessageLoopProxy::current()->PostTask(
- FROM_HERE, base::Bind(callback, SYNC_STATUS_OK));
+ FROM_HERE, base::Bind(callback, status));
}
void FakeRemoteChangeProcessor::FinalizeRemoteSync(