diff --git a/webrtc/base/BUILD.gn b/webrtc/base/BUILD.gn index 8680257ee7..967952ed77 100644 --- a/webrtc/base/BUILD.gn +++ b/webrtc/base/BUILD.gn @@ -353,8 +353,6 @@ static_library("rtc_base") { "bind.h.pump", "callback.h", "callback.h.pump", - "filelock.cc", - "filelock.h", "fileutils_mock.h", "genericslot.h", "genericslot.h.pump", diff --git a/webrtc/base/base.gyp b/webrtc/base/base.gyp index 6e197a58e1..9e7dbace86 100644 --- a/webrtc/base/base.gyp +++ b/webrtc/base/base.gyp @@ -144,8 +144,6 @@ 'diskcache.h', 'diskcache_win32.cc', 'diskcache_win32.h', - 'filelock.cc', - 'filelock.h', 'fileutils.cc', 'fileutils.h', 'fileutils_mock.h', @@ -386,8 +384,6 @@ 'dbus.h', 'diskcache_win32.cc', 'diskcache_win32.h', - 'filelock.cc', - 'filelock.h', 'fileutils_mock.h', 'genericslot.h', 'httpserver.cc', diff --git a/webrtc/base/base_tests.gyp b/webrtc/base/base_tests.gyp index d9e560e1c4..3c500e03c2 100644 --- a/webrtc/base/base_tests.gyp +++ b/webrtc/base/base_tests.gyp @@ -64,7 +64,6 @@ 'event_tracer_unittest.cc', 'event_unittest.cc', 'exp_filter_unittest.cc', - 'filelock_unittest.cc', 'fileutils_unittest.cc', 'helpers_unittest.cc', 'httpbase_unittest.cc', diff --git a/webrtc/base/bitbuffer_unittest.cc b/webrtc/base/bitbuffer_unittest.cc index 21cffd67a3..89d3524677 100644 --- a/webrtc/base/bitbuffer_unittest.cc +++ b/webrtc/base/bitbuffer_unittest.cc @@ -164,8 +164,12 @@ TEST(BitBufferTest, SetOffsetValues) { EXPECT_EQ(0u, bit_offset); EXPECT_FALSE(buffer.Seek(4, 1)); + // Disable death test on Android because it relies on fork() and doesn't play + // nicely. +#if !defined(WEBRTC_ANDROID) // Passing a NULL out parameter is death. EXPECT_DEATH(buffer.GetCurrentOffset(&byte_offset, NULL), ""); +#endif } uint64 GolombEncoded(uint32 val) { diff --git a/webrtc/base/filelock.cc b/webrtc/base/filelock.cc deleted file mode 100644 index fc921febcd..0000000000 --- a/webrtc/base/filelock.cc +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2009 The WebRTC Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/base/filelock.h" - -#include "webrtc/base/fileutils.h" -#include "webrtc/base/logging.h" -#include "webrtc/base/pathutils.h" -#include "webrtc/base/stream.h" - -namespace rtc { - -FileLock::FileLock(const std::string& path, FileStream* file) - : path_(path), file_(file) { -} - -FileLock::~FileLock() { - MaybeUnlock(); -} - -void FileLock::Unlock() { - LOG_F(LS_INFO); - MaybeUnlock(); -} - -void FileLock::MaybeUnlock() { - if (file_) { - LOG(LS_INFO) << "Unlocking:" << path_; - file_->Close(); - Filesystem::DeleteFile(path_); - file_.reset(); - } -} - -FileLock* FileLock::TryLock(const std::string& path) { - FileStream* stream = new FileStream(); - bool ok = false; -#if defined(WEBRTC_WIN) - // Open and lock in a single operation. - ok = stream->OpenShare(path, "a", _SH_DENYRW, NULL); -#else // WEBRTC_LINUX && !WEBRTC_ANDROID and WEBRTC_MAC && !defined(WEBRTC_IOS) - ok = stream->Open(path, "a", NULL) && stream->TryLock(); -#endif - if (ok) { - return new FileLock(path, stream); - } else { - // Something failed, either we didn't succeed to open the - // file or we failed to lock it. Anyway remove the heap - // allocated object and then return NULL to indicate failure. - delete stream; - return NULL; - } -} - -} // namespace rtc diff --git a/webrtc/base/filelock.h b/webrtc/base/filelock.h deleted file mode 100644 index 0de7dfc4eb..0000000000 --- a/webrtc/base/filelock.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2009 The WebRTC Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_BASE_FILELOCK_H_ -#define WEBRTC_BASE_FILELOCK_H_ - -#include - -#include "webrtc/base/constructormagic.h" -#include "webrtc/base/scoped_ptr.h" - -namespace rtc { - -class FileStream; - -// Implements a very simple cross process lock based on a file. -// When Lock(...) is called we try to open/create the file in read/write -// mode without any sharing. (Or locking it with flock(...) on Unix) -// If the process crash the OS will make sure that the file descriptor -// is released and another process can accuire the lock. -// This doesn't work on ancient OSX/Linux versions if used on NFS. -// (Nfs-client before: ~2.6 and Linux Kernel < 2.6.) -class FileLock { - public: - virtual ~FileLock(); - - // Attempts to lock the file. The caller owns the returned - // lock object. Returns NULL if the file already was locked. - static FileLock* TryLock(const std::string& path); - void Unlock(); - - protected: - FileLock(const std::string& path, FileStream* file); - - private: - void MaybeUnlock(); - - std::string path_; - scoped_ptr file_; - - DISALLOW_COPY_AND_ASSIGN(FileLock); -}; - -} // namespace rtc - -#endif // WEBRTC_BASE_FILELOCK_H_ diff --git a/webrtc/base/filelock_unittest.cc b/webrtc/base/filelock_unittest.cc deleted file mode 100644 index cf2d3fef9b..0000000000 --- a/webrtc/base/filelock_unittest.cc +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2009 The WebRTC Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include - -#include "webrtc/base/event.h" -#include "webrtc/base/filelock.h" -#include "webrtc/base/fileutils.h" -#include "webrtc/base/gunit.h" -#include "webrtc/base/pathutils.h" -#include "webrtc/base/scoped_ptr.h" -#include "webrtc/base/thread.h" -#include "webrtc/test/testsupport/gtest_disable.h" - -namespace rtc { - -const static std::string kLockFile = "TestLockFile"; -const static int kTimeoutMS = 5000; - -class FileLockTest : public testing::Test, public Runnable { - public: - FileLockTest() : done_(false, false), thread_lock_failed_(false) { - } - - virtual void Run(Thread* t) { - scoped_ptr lock(FileLock::TryLock(temp_file_.pathname())); - // The lock is already owned by the main thread of - // this test, therefore the TryLock(...) call should fail. - thread_lock_failed_ = lock.get() == NULL; - done_.Set(); - } - - protected: - virtual void SetUp() { - thread_lock_failed_ = false; - Pathname temp_dir; - Filesystem::GetAppTempFolder(&temp_dir); - temp_file_.SetPathname(rtc::Filesystem::TempFilename(temp_dir, kLockFile)); - } - - void LockOnThread() { - locker_.Start(this); - done_.Wait(kTimeoutMS); - } - - Event done_; - Thread locker_; - bool thread_lock_failed_; - Pathname temp_file_; -}; - -TEST_F(FileLockTest, TestLockFileDeleted) { - scoped_ptr lock(FileLock::TryLock(temp_file_.pathname())); - EXPECT_TRUE(lock.get() != NULL); - EXPECT_FALSE(Filesystem::IsAbsent(temp_file_.pathname())); - lock->Unlock(); - EXPECT_TRUE(Filesystem::IsAbsent(temp_file_.pathname())); -} - -TEST_F(FileLockTest, TestLock) { - scoped_ptr lock(FileLock::TryLock(temp_file_.pathname())); - EXPECT_TRUE(lock.get() != NULL); -} - -TEST_F(FileLockTest, TestLockX2) { - scoped_ptr lock1(FileLock::TryLock(temp_file_.pathname())); - EXPECT_TRUE(lock1.get() != NULL); - - scoped_ptr lock2(FileLock::TryLock(temp_file_.pathname())); - EXPECT_TRUE(lock2.get() == NULL); -} - -TEST_F(FileLockTest, TestThreadedLock) { - scoped_ptr lock(FileLock::TryLock(temp_file_.pathname())); - EXPECT_TRUE(lock.get() != NULL); - - LockOnThread(); - EXPECT_TRUE(thread_lock_failed_); -} - -} // namespace rtc