Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(728)

Side by Side Diff: base/scoped_temp_dir.cc

Issue 5340004: Make ScopedTempDir::Delete return a bool so that its functionality can be te... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/scoped_temp_dir.h ('k') | base/scoped_temp_dir_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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() {
11 } 11 }
12 12
13 ScopedTempDir::~ScopedTempDir() { 13 ScopedTempDir::~ScopedTempDir() {
14 Delete(); 14 if (!path_.empty() && !Delete())
15 LOG(WARNING) << "Could not delete temp dir in dtor.";
15 } 16 }
16 17
17 bool ScopedTempDir::CreateUniqueTempDir() { 18 bool ScopedTempDir::CreateUniqueTempDir() {
18 if (!path_.empty()) 19 if (!path_.empty())
19 return false; 20 return false;
20 21
21 // This "scoped_dir" prefix is only used on Windows and serves as a template 22 // This "scoped_dir" prefix is only used on Windows and serves as a template
22 // for the unique name. 23 // for the unique name.
23 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_dir"), 24 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_dir"),
24 &path_)) 25 &path_))
(...skipping 25 matching lines...) Expand all
50 return false; 51 return false;
51 52
52 if (!file_util::DirectoryExists(path) && 53 if (!file_util::DirectoryExists(path) &&
53 !file_util::CreateDirectory(path)) 54 !file_util::CreateDirectory(path))
54 return false; 55 return false;
55 56
56 path_ = path; 57 path_ = path;
57 return true; 58 return true;
58 } 59 }
59 60
60 void ScopedTempDir::Delete() { 61 bool ScopedTempDir::Delete() {
61 if (!path_.empty() && !file_util::Delete(path_, true)) 62 if (path_.empty())
63 return false;
64
65 bool ret = file_util::Delete(path_, true);
66 if (ret) {
67 // We only clear the path if deleted the directory.
68 path_.clear();
69 } else {
62 LOG(ERROR) << "ScopedTempDir unable to delete " << path_.value(); 70 LOG(ERROR) << "ScopedTempDir unable to delete " << path_.value();
63 path_.clear(); 71 }
72
73 return ret;
64 } 74 }
65 75
66 FilePath ScopedTempDir::Take() { 76 FilePath ScopedTempDir::Take() {
67 FilePath ret = path_; 77 FilePath ret = path_;
68 path_ = FilePath(); 78 path_ = FilePath();
69 return ret; 79 return ret;
70 } 80 }
71 81
72 bool ScopedTempDir::IsValid() const { 82 bool ScopedTempDir::IsValid() const {
73 return !path_.empty() && file_util::DirectoryExists(path_); 83 return !path_.empty() && file_util::DirectoryExists(path_);
74 } 84 }
OLDNEW
« no previous file with comments | « base/scoped_temp_dir.h ('k') | base/scoped_temp_dir_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698