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 "base/files/file_util.h" | 5 #include "base/files/file_util.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <libgen.h> | 10 #include <libgen.h> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include <time.h> | 21 #include <time.h> |
22 #include <unistd.h> | 22 #include <unistd.h> |
23 | 23 |
24 #if defined(OS_MACOSX) | 24 #if defined(OS_MACOSX) |
25 #include <AvailabilityMacros.h> | 25 #include <AvailabilityMacros.h> |
26 #include "base/mac/foundation_util.h" | 26 #include "base/mac/foundation_util.h" |
27 #elif !defined(OS_CHROMEOS) && defined(USE_GLIB) | 27 #elif !defined(OS_CHROMEOS) && defined(USE_GLIB) |
28 #include <glib.h> // for g_get_home_dir() | 28 #include <glib.h> // for g_get_home_dir() |
29 #endif | 29 #endif |
30 | 30 |
31 #include <fstream> | |
32 | |
33 #include "base/basictypes.h" | 31 #include "base/basictypes.h" |
34 #include "base/files/file_enumerator.h" | 32 #include "base/files/file_enumerator.h" |
35 #include "base/files/file_path.h" | 33 #include "base/files/file_path.h" |
36 #include "base/files/scoped_file.h" | 34 #include "base/files/scoped_file.h" |
37 #include "base/logging.h" | 35 #include "base/logging.h" |
38 #include "base/memory/scoped_ptr.h" | 36 #include "base/memory/scoped_ptr.h" |
39 #include "base/memory/singleton.h" | 37 #include "base/memory/singleton.h" |
40 #include "base/path_service.h" | 38 #include "base/path_service.h" |
41 #include "base/posix/eintr_wrapper.h" | 39 #include "base/posix/eintr_wrapper.h" |
42 #include "base/stl_util.h" | 40 #include "base/stl_util.h" |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 if (CallStat(path.value().c_str(), &file_info) != 0) | 419 if (CallStat(path.value().c_str(), &file_info) != 0) |
422 return false; | 420 return false; |
423 | 421 |
424 *mode = file_info.st_mode & FILE_PERMISSION_MASK; | 422 *mode = file_info.st_mode & FILE_PERMISSION_MASK; |
425 return true; | 423 return true; |
426 } | 424 } |
427 | 425 |
428 bool SetPosixFilePermissions(const FilePath& path, | 426 bool SetPosixFilePermissions(const FilePath& path, |
429 int mode) { | 427 int mode) { |
430 ThreadRestrictions::AssertIOAllowed(); | 428 ThreadRestrictions::AssertIOAllowed(); |
431 DCHECK((mode & ~FILE_PERMISSION_MASK) == 0); | 429 DCHECK_EQ(mode & ~FILE_PERMISSION_MASK, 0); |
432 | 430 |
433 // Calls stat() so that we can preserve the higher bits like S_ISGID. | 431 // Calls stat() so that we can preserve the higher bits like S_ISGID. |
434 stat_wrapper_t stat_buf; | 432 stat_wrapper_t stat_buf; |
435 if (CallStat(path.value().c_str(), &stat_buf) != 0) | 433 if (CallStat(path.value().c_str(), &stat_buf) != 0) |
436 return false; | 434 return false; |
437 | 435 |
438 // Clears the existing permission bits, and adds the new ones. | 436 // Clears the existing permission bits, and adds the new ones. |
439 mode_t updated_mode_bits = stat_buf.st_mode & ~FILE_PERMISSION_MASK; | 437 mode_t updated_mode_bits = stat_buf.st_mode & ~FILE_PERMISSION_MASK; |
440 updated_mode_bits |= mode & FILE_PERMISSION_MASK; | 438 updated_mode_bits |= mode & FILE_PERMISSION_MASK; |
441 | 439 |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 result = false; | 921 result = false; |
924 | 922 |
925 return result; | 923 return result; |
926 } | 924 } |
927 #endif // !defined(OS_MACOSX) | 925 #endif // !defined(OS_MACOSX) |
928 | 926 |
929 } // namespace internal | 927 } // namespace internal |
930 | 928 |
931 #endif // !defined(OS_NACL_NONSFI) | 929 #endif // !defined(OS_NACL_NONSFI) |
932 } // namespace base | 930 } // namespace base |
OLD | NEW |