Chromium Code Reviews| Index: components/drive/chromeos/file_cache.cc |
| diff --git a/components/drive/chromeos/file_cache.cc b/components/drive/chromeos/file_cache.cc |
| index 1e6c145d8124d6ff25c04a5f50d414ace9e35c8b..1b8efb73ab48f091505177b90a9d8d6bac03366c 100644 |
| --- a/components/drive/chromeos/file_cache.cc |
| +++ b/components/drive/chromeos/file_cache.cc |
| @@ -52,6 +52,16 @@ base::FilePath GetPathForId(const base::FilePath& cache_directory, |
| base::FilePath::FromUTF8Unsafe(util::EscapeCacheFileName(id))); |
| } |
| +// Returns if the filesystem backing |path| supports file attributes. |
| +// This will return false if the filesystem is for example tmpfs, which is used |
| +// for ephemeral mode. |
| +bool IsFileAttributesSupported(const base::FilePath& path) { |
| + if (getxattr(path.value().c_str(), "user.foo", nullptr, 0) >= 0) { |
| + return true; |
| + } |
| + return errno != ENOTSUP; |
| +} |
| + |
| // Sets extended file attribute as |name| |value| pair. |
| bool SetExtendedFileAttributes(const base::FilePath& path, |
| const std::string& name, const std::string& value) { |
| @@ -92,8 +102,14 @@ FileAttributes GetFileAttributes(const base::FilePath& path) { |
| return flags; |
| } |
| -// Marks the cache file to be removable by cryptohome. |
| +// Marks the cache file to be removable by cryptohome, or do nothing if |
| +// underlying filesystem doesn't support file attributes, as tmpfs for ephemeral |
| +// mode. |
| bool SetRemovable(const base::FilePath& path) { |
| + // For ephemeral mode. |
| + if (!IsFileAttributesSupported(path)) { |
| + return true; |
| + } |
| FileAttributes flags = GetFileAttributes(path); |
| if (flags < 0) return false; |
| if ((flags & FS_NODUMP_FL) == FS_NODUMP_FL) return true; |
| @@ -101,8 +117,14 @@ bool SetRemovable(const base::FilePath& path) { |
| return SetFileAttributes(path, flags | FS_NODUMP_FL); |
| } |
| -// Marks the cache file to be unremovable by cryptohome. |
| +// Marks the cache file to be unremovable by cryptohome, or do nothing if |
| +// underlying filesystem doesn't support file attributes, as tmpfs for ephemeral |
| +// mode. |
| bool UnsetRemovable(const base::FilePath& path) { |
| + // For ephemeral mode. |
| + if (!IsFileAttributesSupported(path)) { |
| + return true; |
| + } |
| FileAttributes flags = GetFileAttributes(path); |
| if (flags < 0) return false; |
| if ((flags & FS_NODUMP_FL) == 0) return true; |
| @@ -113,6 +135,9 @@ bool UnsetRemovable(const base::FilePath& path) { |
| // Marks |path| as drive cache dir. |
| // Returns if the operation succeeded. |
| bool MarkAsDriveCacheDir(const base::FilePath& path) { |
| + if (!IsFileAttributesSupported(path)) { |
|
hashimoto
2016/10/14 04:44:44
Please add a comment like the ones in SetRemovable
oka
2016/10/14 04:50:39
Done.
|
| + return true; |
| + } |
| return SetRemovable(path) |
| && SetExtendedFileAttributes(path, FileCache::kGCacheFilesAttribute, ""); |
| } |