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/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
11 | 11 |
12 ScopedTempDir::ScopedTempDir() { | 12 ScopedTempDir::ScopedTempDir() { |
| 13 LOG(ERROR) << "ScopedTempDir: ctor"; |
13 } | 14 } |
14 | 15 |
15 ScopedTempDir::~ScopedTempDir() { | 16 ScopedTempDir::~ScopedTempDir() { |
| 17 LOG(ERROR) << "~ScopedTempDir: deleting temp dir"; |
16 if (!path_.empty() && !Delete()) | 18 if (!path_.empty() && !Delete()) |
17 DLOG(WARNING) << "Could not delete temp dir in dtor."; | 19 LOG(ERROR) << "Could not delete temp dir in dtor."; |
18 } | 20 } |
19 | 21 |
20 bool ScopedTempDir::CreateUniqueTempDir() { | 22 bool ScopedTempDir::CreateUniqueTempDir() { |
21 if (!path_.empty()) | 23 if (!path_.empty()) |
22 return false; | 24 return false; |
23 | 25 |
24 // This "scoped_dir" prefix is only used on Windows and serves as a template | 26 // This "scoped_dir" prefix is only used on Windows and serves as a template |
25 // for the unique name. | 27 // for the unique name. |
26 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_dir"), &path_)) | 28 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_dir"), &path_)) |
27 return false; | 29 return false; |
(...skipping 23 matching lines...) Expand all Loading... |
51 return false; | 53 return false; |
52 | 54 |
53 if (!DirectoryExists(path) && !base::CreateDirectory(path)) | 55 if (!DirectoryExists(path) && !base::CreateDirectory(path)) |
54 return false; | 56 return false; |
55 | 57 |
56 path_ = path; | 58 path_ = path; |
57 return true; | 59 return true; |
58 } | 60 } |
59 | 61 |
60 bool ScopedTempDir::Delete() { | 62 bool ScopedTempDir::Delete() { |
61 if (path_.empty()) | 63 if (path_.empty()) { |
| 64 LOG(ERROR) << "Delete: path is empty -- returning"; |
62 return false; | 65 return false; |
| 66 } |
63 | 67 |
| 68 LOG(ERROR) << "Delete: deleting file"; |
64 bool ret = base::DeleteFile(path_, true); | 69 bool ret = base::DeleteFile(path_, true); |
65 if (ret) { | 70 if (ret) { |
66 // We only clear the path if deleted the directory. | 71 // We only clear the path if deleted the directory. |
| 72 LOG(ERROR) << "Delete: clearing path"; |
67 path_.clear(); | 73 path_.clear(); |
68 } | 74 } |
69 | 75 |
| 76 LOG(ERROR) << "Delete: returning result: " << ret; |
70 return ret; | 77 return ret; |
71 } | 78 } |
72 | 79 |
73 FilePath ScopedTempDir::Take() { | 80 FilePath ScopedTempDir::Take() { |
74 FilePath ret = path_; | 81 FilePath ret = path_; |
75 path_ = FilePath(); | 82 path_ = FilePath(); |
76 return ret; | 83 return ret; |
77 } | 84 } |
78 | 85 |
79 bool ScopedTempDir::IsValid() const { | 86 bool ScopedTempDir::IsValid() const { |
80 return !path_.empty() && DirectoryExists(path_); | 87 return !path_.empty() && DirectoryExists(path_); |
81 } | 88 } |
82 | 89 |
83 } // namespace base | 90 } // namespace base |
OLD | NEW |