| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <shlobj.h> | 10 #include <shlobj.h> |
| (...skipping 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1381 // Sets the source file to read-only. | 1381 // Sets the source file to read-only. |
| 1382 void SetReadOnly(const FilePath& path, bool read_only) { | 1382 void SetReadOnly(const FilePath& path, bool read_only) { |
| 1383 #if defined(OS_WIN) | 1383 #if defined(OS_WIN) |
| 1384 // On Windows, it involves setting/removing the 'readonly' bit. | 1384 // On Windows, it involves setting/removing the 'readonly' bit. |
| 1385 DWORD attrs = GetFileAttributes(path.value().c_str()); | 1385 DWORD attrs = GetFileAttributes(path.value().c_str()); |
| 1386 ASSERT_NE(INVALID_FILE_ATTRIBUTES, attrs); | 1386 ASSERT_NE(INVALID_FILE_ATTRIBUTES, attrs); |
| 1387 ASSERT_TRUE(SetFileAttributes( | 1387 ASSERT_TRUE(SetFileAttributes( |
| 1388 path.value().c_str(), | 1388 path.value().c_str(), |
| 1389 read_only ? (attrs | FILE_ATTRIBUTE_READONLY) : | 1389 read_only ? (attrs | FILE_ATTRIBUTE_READONLY) : |
| 1390 (attrs & ~FILE_ATTRIBUTE_READONLY))); | 1390 (attrs & ~FILE_ATTRIBUTE_READONLY))); |
| 1391 // Files in the temporary directory should not be indexed ever. If this | 1391 |
| 1392 // assumption change, fix this unit test accordingly. | |
| 1393 // FILE_ATTRIBUTE_NOT_CONTENT_INDEXED doesn't exist on XP. | |
| 1394 DWORD expected = read_only ? | 1392 DWORD expected = read_only ? |
| 1395 ((attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY)) | | 1393 ((attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY)) | |
| 1396 FILE_ATTRIBUTE_READONLY) : | 1394 FILE_ATTRIBUTE_READONLY) : |
| 1397 (attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY)); | 1395 (attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY)); |
| 1398 // TODO(ripp@yandex-team.ru): this seems out of place here. If we really think | 1396 |
| 1399 // it is important to verify that temp files are not indexed there should be | 1397 // Ignore FILE_ATTRIBUTE_NOT_CONTENT_INDEXED if present. |
| 1400 // a dedicated test for that (create a file, inspect the attributes) | 1398 attrs = GetFileAttributes(path.value().c_str()) & |
| 1401 if (win::GetVersion() >= win::VERSION_VISTA) | 1399 ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; |
| 1402 expected |= FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; | |
| 1403 attrs = GetFileAttributes(path.value().c_str()); | |
| 1404 ASSERT_EQ(expected, attrs); | 1400 ASSERT_EQ(expected, attrs); |
| 1405 #else | 1401 #else |
| 1406 // On all other platforms, it involves removing/setting the write bit. | 1402 // On all other platforms, it involves removing/setting the write bit. |
| 1407 mode_t mode = read_only ? S_IRUSR : (S_IRUSR | S_IWUSR); | 1403 mode_t mode = read_only ? S_IRUSR : (S_IRUSR | S_IWUSR); |
| 1408 EXPECT_TRUE(SetPosixFilePermissions( | 1404 EXPECT_TRUE(SetPosixFilePermissions( |
| 1409 path, DirectoryExists(path) ? (mode | S_IXUSR) : mode)); | 1405 path, DirectoryExists(path) ? (mode | S_IXUSR) : mode)); |
| 1410 #endif | 1406 #endif |
| 1411 } | 1407 } |
| 1412 | 1408 |
| 1413 bool IsReadOnly(const FilePath& path) { | 1409 bool IsReadOnly(const FilePath& path) { |
| (...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2606 // Trying to close it should crash. This is important for security. | 2602 // Trying to close it should crash. This is important for security. |
| 2607 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); | 2603 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); |
| 2608 #endif | 2604 #endif |
| 2609 } | 2605 } |
| 2610 | 2606 |
| 2611 #endif // defined(OS_POSIX) | 2607 #endif // defined(OS_POSIX) |
| 2612 | 2608 |
| 2613 } // namespace | 2609 } // namespace |
| 2614 | 2610 |
| 2615 } // namespace base | 2611 } // namespace base |
| OLD | NEW |