Commit 89ddf7b9 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

Disable OS file locking on Fuchsia

Fuchsia doesn't support file locking, i.e. there is no
base::File::Lock(), so components/filesystem was failing to compile.
Added ifdefs so File::Lock() is not used on Fuchsia.

Bug: 737802, 744893
Change-Id: I825fba49b9c6247d1b4c75ca23fce4c150344db1
Reviewed-on: https://chromium-review.googlesource.com/575288
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarElliot Glaysher <erg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487347}
parent 75ca910c
......@@ -62,6 +62,7 @@ bool FileImpl::IsValid() const {
return file_.IsValid();
}
#if !defined(OS_FUCHSIA)
base::File::Error FileImpl::RawLockFile() {
return file_.Lock();
}
......@@ -69,6 +70,7 @@ base::File::Error FileImpl::RawLockFile() {
base::File::Error FileImpl::RawUnlockFile() {
return file_.Unlock();
}
#endif // !OS_FUCHSIA
void FileImpl::Close(CloseCallback callback) {
if (!file_.IsValid()) {
......
......@@ -10,6 +10,7 @@
#include "base/files/file.h"
#include "base/files/scoped_file.h"
#include "base/macros.h"
#include "build/build_config.h"
#include "components/filesystem/public/interfaces/directory.mojom.h"
#include "mojo/public/cpp/bindings/interface_request.h"
......@@ -37,10 +38,12 @@ class FileImpl : public mojom::File {
// Returns whether the underlying file handle is valid.
bool IsValid() const;
#if !defined(OS_FUCHSIA)
// Attempts to perform the native operating system's locking operations on
// the internal mojom::File handle
// the internal mojom::File handle. Not supported on Fuchsia.
base::File::Error RawLockFile();
base::File::Error RawUnlockFile();
#endif // !OS_FUCHSIA
const base::FilePath& path() const { return path_; }
......
......@@ -4,6 +4,7 @@
#include "components/filesystem/lock_table.h"
#include "build/build_config.h"
#include "components/filesystem/file_impl.h"
namespace filesystem {
......@@ -22,11 +23,20 @@ base::File::Error LockTable::LockFile(FileImpl* file) {
return base::File::FILE_ERROR_FAILED;
}
#if !defined(OS_FUCHSIA)
// Fuchsia doesn't provide a file locking mechanism, so file locks work only
// within a single process. File locking is used only by LevelDB which stores
// all files in the profile directory and normally there shouldn't be more
// than a single chrome process per profile. So in-process locks should be
// sufficient.
// TODO(fuchsia): Investigate if it's necessary to implement cross-process
// file locks. crbug.com/744893 .
base::File::Error lock_err = file->RawLockFile();
if (lock_err != base::File::FILE_OK) {
// Locking failed for some reason.
return lock_err;
}
#endif // !OS_FUCHSIA
locked_files_.insert(file->path());
return base::File::FILE_OK;
......@@ -35,12 +45,14 @@ base::File::Error LockTable::LockFile(FileImpl* file) {
base::File::Error LockTable::UnlockFile(FileImpl* file) {
auto it = locked_files_.find(file->path());
if (it != locked_files_.end()) {
#if !defined(OS_FUCHSIA)
base::File::Error lock_err = file->RawUnlockFile();
if (lock_err != base::File::FILE_OK) {
// TODO(erg): When can we fail to release a lock?
NOTREACHED();
return lock_err;
}
#endif // !OS_FUCHSIA
locked_files_.erase(it);
}
......
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