Commit fad625e2 authored by tzik@chromium.org's avatar tzik@chromium.org

Update mtime of directory when containing entry changed.

BUG=None
TEST='ObfuscatedFileUtilTest.TestDirectoryTimestamp'


Review URL: http://codereview.chromium.org/8728029

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113565 0039d316-1c4b-4281-b951-d872f2087c98
parent 06fb8702
...@@ -92,6 +92,13 @@ void UpdatePathQuotaUsage( ...@@ -92,6 +92,13 @@ void UpdatePathQuotaUsage(
type, growth); type, growth);
} }
void TouchDirectory(fileapi::FileSystemDirectoryDatabase* db,
fileapi::FileSystemDirectoryDatabase::FileId dir_id) {
DCHECK(db);
if (!db->UpdateModificationTime(dir_id, base::Time::Now()))
NOTREACHED();
}
const FilePath::CharType kLegacyDataDirectory[] = FILE_PATH_LITERAL("Legacy"); const FilePath::CharType kLegacyDataDirectory[] = FILE_PATH_LITERAL("Legacy");
const FilePath::CharType kTemporaryDirectoryName[] = FILE_PATH_LITERAL("t"); const FilePath::CharType kTemporaryDirectoryName[] = FILE_PATH_LITERAL("t");
...@@ -391,6 +398,7 @@ PlatformFileError ObfuscatedFileUtil::CreateDirectory( ...@@ -391,6 +398,7 @@ PlatformFileError ObfuscatedFileUtil::CreateDirectory(
} }
if (!recursive && components.size() - index > 1) if (!recursive && components.size() - index > 1)
return base::PLATFORM_FILE_ERROR_NOT_FOUND; return base::PLATFORM_FILE_ERROR_NOT_FOUND;
bool first = true;
for (; index < components.size(); ++index) { for (; index < components.size(); ++index) {
FileInfo file_info; FileInfo file_info;
file_info.name = components[index]; file_info.name = components[index];
...@@ -406,6 +414,10 @@ PlatformFileError ObfuscatedFileUtil::CreateDirectory( ...@@ -406,6 +414,10 @@ PlatformFileError ObfuscatedFileUtil::CreateDirectory(
} }
UpdatePathQuotaUsage(context, context->src_origin_url(), UpdatePathQuotaUsage(context, context->src_origin_url(),
context->src_type(), 1, file_info.name.size()); context->src_type(), 1, file_info.name.size());
if (first) {
first = false;
TouchDirectory(db, file_info.parent_id);
}
} }
return base::PLATFORM_FILE_OK; return base::PLATFORM_FILE_OK;
} }
...@@ -533,8 +545,7 @@ PlatformFileError ObfuscatedFileUtil::Touch( ...@@ -533,8 +545,7 @@ PlatformFileError ObfuscatedFileUtil::Touch(
return base::PLATFORM_FILE_ERROR_FAILED; return base::PLATFORM_FILE_ERROR_FAILED;
} }
if (file_info.is_directory()) { if (file_info.is_directory()) {
file_info.modification_time = last_modified_time; if (!db->UpdateModificationTime(file_id, last_modified_time))
if (!db->UpdateFileInfo(file_id, file_info))
return base::PLATFORM_FILE_ERROR_FAILED; return base::PLATFORM_FILE_ERROR_FAILED;
return base::PLATFORM_FILE_OK; return base::PLATFORM_FILE_OK;
} }
...@@ -682,8 +693,11 @@ PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile( ...@@ -682,8 +693,11 @@ PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile(
if (overwrite) { if (overwrite) {
FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(), FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(),
context->src_type(), dest_file_info.data_path); context->src_type(), dest_file_info.data_path);
return underlying_file_util()->CopyOrMoveFile(context, PlatformFileError error = underlying_file_util()->CopyOrMoveFile(context,
src_data_path, dest_data_path, copy); src_data_path, dest_data_path, copy);
if (error == base::PLATFORM_FILE_OK)
TouchDirectory(db, dest_file_info.parent_id);
return error;
} else { } else {
FileId dest_parent_id; FileId dest_parent_id;
if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) {
...@@ -712,6 +726,8 @@ PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile( ...@@ -712,6 +726,8 @@ PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile(
UpdatePathQuotaUsage(context, context->src_origin_url(), UpdatePathQuotaUsage(context, context->src_origin_url(),
context->src_type(), -1, context->src_type(), -1,
-static_cast<int64>(src_file_info.name.size())); -static_cast<int64>(src_file_info.name.size()));
TouchDirectory(db, src_file_info.parent_id);
TouchDirectory(db, dest_file_info.parent_id);
return base::PLATFORM_FILE_OK; return base::PLATFORM_FILE_OK;
} else { } else {
FileId dest_parent_id; FileId dest_parent_id;
...@@ -724,6 +740,7 @@ PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile( ...@@ -724,6 +740,7 @@ PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile(
static_cast<int64>(dest_file_path.BaseName().value().size()) static_cast<int64>(dest_file_path.BaseName().value().size())
- static_cast<int64>(src_file_info.name.size()))) - static_cast<int64>(src_file_info.name.size())))
return base::PLATFORM_FILE_ERROR_NO_SPACE; return base::PLATFORM_FILE_ERROR_NO_SPACE;
FileId src_parent_id = src_file_info.parent_id;
src_file_info.parent_id = dest_parent_id; src_file_info.parent_id = dest_parent_id;
src_file_info.name = dest_file_path.BaseName().value(); src_file_info.name = dest_file_path.BaseName().value();
if (!db->UpdateFileInfo(src_file_id, src_file_info)) if (!db->UpdateFileInfo(src_file_id, src_file_info))
...@@ -732,6 +749,8 @@ PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile( ...@@ -732,6 +749,8 @@ PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile(
context, context->src_origin_url(), context->src_type(), 0, context, context->src_origin_url(), context->src_type(), 0,
static_cast<int64>(dest_file_path.BaseName().value().size()) - static_cast<int64>(dest_file_path.BaseName().value().size()) -
static_cast<int64>(src_file_path.BaseName().value().size())); static_cast<int64>(src_file_path.BaseName().value().size()));
TouchDirectory(db, src_parent_id);
TouchDirectory(db, dest_parent_id);
return base::PLATFORM_FILE_OK; return base::PLATFORM_FILE_OK;
} }
} }
...@@ -803,6 +822,7 @@ PlatformFileError ObfuscatedFileUtil::DeleteFile( ...@@ -803,6 +822,7 @@ PlatformFileError ObfuscatedFileUtil::DeleteFile(
if (base::PLATFORM_FILE_OK != if (base::PLATFORM_FILE_OK !=
underlying_file_util()->DeleteFile(context, data_path)) underlying_file_util()->DeleteFile(context, data_path))
LOG(WARNING) << "Leaked a backing file."; LOG(WARNING) << "Leaked a backing file.";
TouchDirectory(db, file_info.parent_id);
return base::PLATFORM_FILE_OK; return base::PLATFORM_FILE_OK;
} }
...@@ -826,6 +846,7 @@ PlatformFileError ObfuscatedFileUtil::DeleteSingleDirectory( ...@@ -826,6 +846,7 @@ PlatformFileError ObfuscatedFileUtil::DeleteSingleDirectory(
AllocateQuotaForPath(context, -1, -static_cast<int64>(file_info.name.size())); AllocateQuotaForPath(context, -1, -static_cast<int64>(file_info.name.size()));
UpdatePathQuotaUsage(context, context->src_origin_url(), context->src_type(), UpdatePathQuotaUsage(context, context->src_origin_url(), context->src_type(),
-1, -static_cast<int64>(file_info.name.size())); -1, -static_cast<int64>(file_info.name.size()));
TouchDirectory(db, file_info.parent_id);
return base::PLATFORM_FILE_OK; return base::PLATFORM_FILE_OK;
} }
...@@ -1117,6 +1138,7 @@ PlatformFileError ObfuscatedFileUtil::CreateFile( ...@@ -1117,6 +1138,7 @@ PlatformFileError ObfuscatedFileUtil::CreateFile(
return base::PLATFORM_FILE_ERROR_FAILED; return base::PLATFORM_FILE_ERROR_FAILED;
} }
UpdatePathQuotaUsage(context, origin_url, type, 1, file_info->name.size()); UpdatePathQuotaUsage(context, origin_url, type, 1, file_info->name.size());
TouchDirectory(db, file_info->parent_id);
return base::PLATFORM_FILE_OK; return base::PLATFORM_FILE_OK;
} }
......
...@@ -42,9 +42,6 @@ class FileSystemOperationContext; ...@@ -42,9 +42,6 @@ class FileSystemOperationContext;
// SandboxMountPointProvider [and the task it uses to drop the reference] and // SandboxMountPointProvider [and the task it uses to drop the reference] and
// SandboxMountPointProvider::GetFileSystemRootPathTask. Without that last one, // SandboxMountPointProvider::GetFileSystemRootPathTask. Without that last one,
// we wouldn't need ref counting. // we wouldn't need ref counting.
//
// TODO(ericu): We don't ever update directory mtimes; which operations should
// do that?
class ObfuscatedFileUtil : public FileSystemFileUtil, class ObfuscatedFileUtil : public FileSystemFileUtil,
public base::RefCountedThreadSafe<ObfuscatedFileUtil> { public base::RefCountedThreadSafe<ObfuscatedFileUtil> {
public: public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment