| 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/scoped_temp_dir.h" | 5 #include "base/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 ScopedTempDir::ScopedTempDir() { | 10 ScopedTempDir::ScopedTempDir() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 if (!file_util::DirectoryExists(path) && | 53 if (!file_util::DirectoryExists(path) && |
| 54 !file_util::CreateDirectory(path)) | 54 !file_util::CreateDirectory(path)) |
| 55 return false; | 55 return false; |
| 56 | 56 |
| 57 path_ = path; | 57 path_ = path; |
| 58 return true; | 58 return true; |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool ScopedTempDir::Delete() { | 61 bool ScopedTempDir::Delete() { |
| 62 LOG(WARNING) << "Deleting " << path_.LossyDisplayName() << " " << this; | |
| 63 if (path_.empty()) | 62 if (path_.empty()) |
| 64 return false; | 63 return false; |
| 65 | 64 |
| 66 bool ret = file_util::Delete(path_, true); | 65 bool ret = file_util::Delete(path_, true); |
| 67 if (ret) { | 66 if (ret) { |
| 68 // We only clear the path if deleted the directory. | 67 // We only clear the path if deleted the directory. |
| 69 path_.clear(); | 68 path_.clear(); |
| 70 } else { | |
| 71 DLOG(ERROR) << "ScopedTempDir unable to delete " << path_.value(); | |
| 72 } | 69 } |
| 73 | 70 |
| 74 return ret; | 71 return ret; |
| 75 } | 72 } |
| 76 | 73 |
| 77 FilePath ScopedTempDir::Take() { | 74 FilePath ScopedTempDir::Take() { |
| 78 FilePath ret = path_; | 75 FilePath ret = path_; |
| 79 path_ = FilePath(); | 76 path_ = FilePath(); |
| 80 return ret; | 77 return ret; |
| 81 } | 78 } |
| 82 | 79 |
| 83 bool ScopedTempDir::IsValid() const { | 80 bool ScopedTempDir::IsValid() const { |
| 84 return !path_.empty() && file_util::DirectoryExists(path_); | 81 return !path_.empty() && file_util::DirectoryExists(path_); |
| 85 } | 82 } |
| OLD | NEW |