remove filelock which is now unused
R=pthatcher@webrtc.org Review URL: https://webrtc-codereview.appspot.com/51859004 Cr-Commit-Position: refs/heads/master@{#9222}
This commit is contained in:
parent
2f5be9ad63
commit
5ece00f7fa
@ -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",
|
||||
|
@ -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',
|
||||
|
@ -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',
|
||||
|
@ -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) {
|
||||
|
@ -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
|
@ -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 <string>
|
||||
|
||||
#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<FileStream> file_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FileLock);
|
||||
};
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // WEBRTC_BASE_FILELOCK_H_
|
@ -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 <string>
|
||||
|
||||
#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<FileLock> 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<FileLock> 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<FileLock> lock(FileLock::TryLock(temp_file_.pathname()));
|
||||
EXPECT_TRUE(lock.get() != NULL);
|
||||
}
|
||||
|
||||
TEST_F(FileLockTest, TestLockX2) {
|
||||
scoped_ptr<FileLock> lock1(FileLock::TryLock(temp_file_.pathname()));
|
||||
EXPECT_TRUE(lock1.get() != NULL);
|
||||
|
||||
scoped_ptr<FileLock> lock2(FileLock::TryLock(temp_file_.pathname()));
|
||||
EXPECT_TRUE(lock2.get() == NULL);
|
||||
}
|
||||
|
||||
TEST_F(FileLockTest, TestThreadedLock) {
|
||||
scoped_ptr<FileLock> lock(FileLock::TryLock(temp_file_.pathname()));
|
||||
EXPECT_TRUE(lock.get() != NULL);
|
||||
|
||||
LockOnThread();
|
||||
EXPECT_TRUE(thread_lock_failed_);
|
||||
}
|
||||
|
||||
} // namespace rtc
|
Loading…
x
Reference in New Issue
Block a user