OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
(...skipping 16 matching lines...) Expand all Loading... |
27 return false; | 27 return false; |
28 | 28 |
29 return true; | 29 return true; |
30 } | 30 } |
31 | 31 |
32 bool ScopedTempDir::CreateUniqueTempDirUnderPath(const FilePath& base_path) { | 32 bool ScopedTempDir::CreateUniqueTempDirUnderPath(const FilePath& base_path) { |
33 if (!path_.empty()) | 33 if (!path_.empty()) |
34 return false; | 34 return false; |
35 | 35 |
36 // If |base_path| does not exist, create it. | 36 // If |base_path| does not exist, create it. |
37 if (!file_util::CreateDirectory(base_path)) | 37 if (!base::CreateDirectory(base_path)) |
38 return false; | 38 return false; |
39 | 39 |
40 // Create a new, uniquely named directory under |base_path|. | 40 // Create a new, uniquely named directory under |base_path|. |
41 if (!base::CreateTemporaryDirInDir(base_path, | 41 if (!base::CreateTemporaryDirInDir(base_path, |
42 FILE_PATH_LITERAL("scoped_dir_"), | 42 FILE_PATH_LITERAL("scoped_dir_"), |
43 &path_)) | 43 &path_)) |
44 return false; | 44 return false; |
45 | 45 |
46 return true; | 46 return true; |
47 } | 47 } |
48 | 48 |
49 bool ScopedTempDir::Set(const FilePath& path) { | 49 bool ScopedTempDir::Set(const FilePath& path) { |
50 if (!path_.empty()) | 50 if (!path_.empty()) |
51 return false; | 51 return false; |
52 | 52 |
53 if (!DirectoryExists(path) && !file_util::CreateDirectory(path)) | 53 if (!DirectoryExists(path) && !base::CreateDirectory(path)) |
54 return false; | 54 return false; |
55 | 55 |
56 path_ = path; | 56 path_ = path; |
57 return true; | 57 return true; |
58 } | 58 } |
59 | 59 |
60 bool ScopedTempDir::Delete() { | 60 bool ScopedTempDir::Delete() { |
61 if (path_.empty()) | 61 if (path_.empty()) |
62 return false; | 62 return false; |
63 | 63 |
(...skipping 10 matching lines...) Expand all Loading... |
74 FilePath ret = path_; | 74 FilePath ret = path_; |
75 path_ = FilePath(); | 75 path_ = FilePath(); |
76 return ret; | 76 return ret; |
77 } | 77 } |
78 | 78 |
79 bool ScopedTempDir::IsValid() const { | 79 bool ScopedTempDir::IsValid() const { |
80 return !path_.empty() && DirectoryExists(path_); | 80 return !path_.empty() && DirectoryExists(path_); |
81 } | 81 } |
82 | 82 |
83 } // namespace base | 83 } // namespace base |
OLD | NEW |