| Index: webrtc/base/win32filesystem.cc
|
| diff --git a/webrtc/base/win32filesystem.cc b/webrtc/base/win32filesystem.cc
|
| index 84574032e6892ad0f09bf7989be412cb9e47bc33..ac49c640752a52a3b7a0c632fda97ec611723291 100644
|
| --- a/webrtc/base/win32filesystem.cc
|
| +++ b/webrtc/base/win32filesystem.cc
|
| @@ -72,114 +72,6 @@ FileStream *Win32Filesystem::OpenFile(const Pathname &filename,
|
| return fs;
|
| }
|
|
|
| -bool Win32Filesystem::CreatePrivateFile(const Pathname &filename) {
|
| - // To make the file private to the current user, we first must construct a
|
| - // SECURITY_DESCRIPTOR specifying an ACL. This code is mostly based upon
|
| - // http://msdn.microsoft.com/en-us/library/ms707085%28VS.85%29.aspx
|
| -
|
| - // Get the current process token.
|
| - HANDLE process_token = INVALID_HANDLE_VALUE;
|
| - if (!::OpenProcessToken(::GetCurrentProcess(),
|
| - TOKEN_QUERY,
|
| - &process_token)) {
|
| - LOG_ERR(LS_ERROR) << "OpenProcessToken() failed";
|
| - return false;
|
| - }
|
| -
|
| - // Get the size of its TOKEN_USER structure. Return value is not checked
|
| - // because we expect it to fail.
|
| - DWORD token_user_size = 0;
|
| - (void)::GetTokenInformation(process_token,
|
| - TokenUser,
|
| - NULL,
|
| - 0,
|
| - &token_user_size);
|
| -
|
| - // Get the TOKEN_USER structure.
|
| - std::unique_ptr<char[]> token_user_bytes(new char[token_user_size]);
|
| - PTOKEN_USER token_user = reinterpret_cast<PTOKEN_USER>(
|
| - token_user_bytes.get());
|
| - memset(token_user, 0, token_user_size);
|
| - BOOL success = ::GetTokenInformation(process_token,
|
| - TokenUser,
|
| - token_user,
|
| - token_user_size,
|
| - &token_user_size);
|
| - // We're now done with this.
|
| - ::CloseHandle(process_token);
|
| - if (!success) {
|
| - LOG_ERR(LS_ERROR) << "GetTokenInformation() failed";
|
| - return false;
|
| - }
|
| -
|
| - if (!IsValidSid(token_user->User.Sid)) {
|
| - LOG_ERR(LS_ERROR) << "Current process has invalid user SID";
|
| - return false;
|
| - }
|
| -
|
| - // Compute size needed for an ACL that allows access to just this user.
|
| - int acl_size = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) +
|
| - GetLengthSid(token_user->User.Sid);
|
| -
|
| - // Allocate it.
|
| - std::unique_ptr<char[]> acl_bytes(new char[acl_size]);
|
| - PACL acl = reinterpret_cast<PACL>(acl_bytes.get());
|
| - memset(acl, 0, acl_size);
|
| - if (!::InitializeAcl(acl, acl_size, ACL_REVISION)) {
|
| - LOG_ERR(LS_ERROR) << "InitializeAcl() failed";
|
| - return false;
|
| - }
|
| -
|
| - // Allow access to only the current user.
|
| - if (!::AddAccessAllowedAce(acl,
|
| - ACL_REVISION,
|
| - GENERIC_READ | GENERIC_WRITE | STANDARD_RIGHTS_ALL,
|
| - token_user->User.Sid)) {
|
| - LOG_ERR(LS_ERROR) << "AddAccessAllowedAce() failed";
|
| - return false;
|
| - }
|
| -
|
| - // Now make the security descriptor.
|
| - SECURITY_DESCRIPTOR security_descriptor;
|
| - if (!::InitializeSecurityDescriptor(&security_descriptor,
|
| - SECURITY_DESCRIPTOR_REVISION)) {
|
| - LOG_ERR(LS_ERROR) << "InitializeSecurityDescriptor() failed";
|
| - return false;
|
| - }
|
| -
|
| - // Put the ACL in it.
|
| - if (!::SetSecurityDescriptorDacl(&security_descriptor,
|
| - TRUE,
|
| - acl,
|
| - FALSE)) {
|
| - LOG_ERR(LS_ERROR) << "SetSecurityDescriptorDacl() failed";
|
| - return false;
|
| - }
|
| -
|
| - // Finally create the file.
|
| - SECURITY_ATTRIBUTES security_attributes;
|
| - security_attributes.nLength = sizeof(security_attributes);
|
| - security_attributes.lpSecurityDescriptor = &security_descriptor;
|
| - security_attributes.bInheritHandle = FALSE;
|
| - HANDLE handle = ::CreateFile(
|
| - ToUtf16(filename.pathname()).c_str(),
|
| - GENERIC_READ | GENERIC_WRITE,
|
| - FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
|
| - &security_attributes,
|
| - CREATE_NEW,
|
| - 0,
|
| - NULL);
|
| - if (INVALID_HANDLE_VALUE == handle) {
|
| - LOG_ERR(LS_ERROR) << "CreateFile() failed";
|
| - return false;
|
| - }
|
| - if (!::CloseHandle(handle)) {
|
| - LOG_ERR(LS_ERROR) << "CloseFile() failed";
|
| - // Continue.
|
| - }
|
| - return true;
|
| -}
|
| -
|
| bool Win32Filesystem::DeleteFile(const Pathname &filename) {
|
| LOG(LS_INFO) << "Deleting file " << filename.pathname();
|
| if (!IsFile(filename)) {
|
| @@ -241,28 +133,6 @@ bool Win32Filesystem::MoveFile(const Pathname &old_path,
|
| ToUtf16(new_path.pathname()).c_str()) != 0;
|
| }
|
|
|
| -bool Win32Filesystem::MoveFolder(const Pathname &old_path,
|
| - const Pathname &new_path) {
|
| - if (!IsFolder(old_path)) {
|
| - ASSERT(IsFolder(old_path));
|
| - return false;
|
| - }
|
| - LOG(LS_INFO) << "Moving " << old_path.pathname()
|
| - << " to " << new_path.pathname();
|
| - if (::MoveFile(ToUtf16(old_path.pathname()).c_str(),
|
| - ToUtf16(new_path.pathname()).c_str()) == 0) {
|
| - if (::GetLastError() != ERROR_NOT_SAME_DEVICE) {
|
| - LOG_GLE(LS_ERROR) << "Failed to move file";
|
| - return false;
|
| - }
|
| - if (!CopyFolder(old_path, new_path))
|
| - return false;
|
| - if (!DeleteFolderAndContents(old_path))
|
| - return false;
|
| - }
|
| - return true;
|
| -}
|
| -
|
| bool Win32Filesystem::IsFolder(const Pathname &path) {
|
| WIN32_FILE_ATTRIBUTE_DATA data = {0};
|
| if (0 == ::GetFileAttributesEx(ToUtf16(path.pathname()).c_str(),
|
| @@ -423,41 +293,4 @@ bool Win32Filesystem::GetDiskFreeSpace(const Pathname& path,
|
| }
|
| }
|
|
|
| -Pathname Win32Filesystem::GetCurrentDirectory() {
|
| - Pathname cwd;
|
| - int path_len = 0;
|
| - std::unique_ptr<wchar_t[]> path;
|
| - do {
|
| - int needed = ::GetCurrentDirectory(path_len, path.get());
|
| - if (needed == 0) {
|
| - // Error.
|
| - LOG_GLE(LS_ERROR) << "::GetCurrentDirectory() failed";
|
| - return cwd; // returns empty pathname
|
| - }
|
| - if (needed <= path_len) {
|
| - // It wrote successfully.
|
| - break;
|
| - }
|
| - // Else need to re-alloc for "needed".
|
| - path.reset(new wchar_t[needed]);
|
| - path_len = needed;
|
| - } while (true);
|
| - cwd.SetFolder(ToUtf8(path.get()));
|
| - return cwd;
|
| -}
|
| -
|
| -// TODO: Consider overriding DeleteFolderAndContents for speed and potentially
|
| -// better OS integration (recycle bin?)
|
| -/*
|
| - std::wstring temp_path16 = ToUtf16(temp_path.pathname());
|
| - temp_path16.append(1, '*');
|
| - temp_path16.append(1, '\0');
|
| -
|
| - SHFILEOPSTRUCT file_op = { 0 };
|
| - file_op.wFunc = FO_DELETE;
|
| - file_op.pFrom = temp_path16.c_str();
|
| - file_op.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT;
|
| - return (0 == SHFileOperation(&file_op));
|
| -*/
|
| -
|
| } // namespace rtc
|
|
|