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

Side by Side Diff: base/test_file_util_posix.cc

Issue 40213: Reverting 11102.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 9 months 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/file_util_posix.cc ('k') | no next file » | 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/test_file_util.h" 5 #include "base/test_file_util.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fts.h> 8 #include <fts.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 26 matching lines...) Expand all
37 } 37 }
38 38
39 int error = 0; 39 int error = 0;
40 FTSENT* ent; 40 FTSENT* ent;
41 while (!error && (ent = fts_read(fts)) != NULL) { 41 while (!error && (ent = fts_read(fts)) != NULL) {
42 // ent->fts_path is the source path, including from_path, so paste 42 // ent->fts_path is the source path, including from_path, so paste
43 // the suffix after from_path onto to_path to create the target_path. 43 // the suffix after from_path onto to_path to create the target_path.
44 std::string suffix(&ent->fts_path[from_path.value().size()]); 44 std::string suffix(&ent->fts_path[from_path.value().size()]);
45 // Strip the leading '/' (if any). 45 // Strip the leading '/' (if any).
46 if (!suffix.empty()) { 46 if (!suffix.empty()) {
47 DCHECK_EQ('/', suffix[0]); 47 DCHECK(suffix[0] == '/');
48 suffix.erase(0, 1); 48 suffix.erase(0, 1);
49 } 49 }
50 const FilePath target_path = to_path.Append(suffix); 50 const FilePath target_path = to_path.Append(suffix);
51 switch (ent->fts_info) { 51 switch (ent->fts_info) {
52 case FTS_D: // Preorder directory. 52 case FTS_D: // Preorder directory.
53 // Try creating the target dir, continuing on it if it exists already. 53 // Try creating the target dir, continuing on it if it exists already.
54 // Rely on the user's umask to produce correct permissions.
55 if (mkdir(target_path.value().c_str(), 0777) != 0) { 54 if (mkdir(target_path.value().c_str(), 0777) != 0) {
56 if (errno != EEXIST) 55 if (errno != EEXIST)
57 error = errno; 56 error = errno;
58 } 57 }
59 break; 58 break;
60 case FTS_F: // Regular file. 59 case FTS_F: // Regular file.
61 case FTS_NSOK: // File, no stat info requested. 60 case FTS_NSOK: // File, no stat info requested.
62 { 61 {
63 errno = 0; 62 errno = 0;
64 FilePath source_path(ent->fts_path); 63 FilePath source_path(ent->fts_path);
(...skipping 16 matching lines...) Expand all
81 error = errno; 80 error = errno;
82 break; 81 break;
83 case FTS_DNR: // Directory cannot be read. 82 case FTS_DNR: // Directory cannot be read.
84 case FTS_ERR: // Error. 83 case FTS_ERR: // Error.
85 case FTS_NS: // Stat failed. 84 case FTS_NS: // Stat failed.
86 // Abort with the error. 85 // Abort with the error.
87 error = ent->fts_errno; 86 error = ent->fts_errno;
88 break; 87 break;
89 case FTS_SL: // Symlink. 88 case FTS_SL: // Symlink.
90 case FTS_SLNONE: // Symlink with broken target. 89 case FTS_SLNONE: // Symlink with broken target.
91 LOG(WARNING) << "skipping symbolic link: " << ent->fts_path; 90 LOG(WARNING) << "skipping symbolic link.";
92 continue; 91 continue;
93 case FTS_DEFAULT: // Some other sort of file. 92 case FTS_DEFAULT: // Some other sort of file.
94 LOG(WARNING) << "skipping file of unknown type: " << ent->fts_path; 93 LOG(WARNING) << "skipping weird file.";
95 continue; 94 continue;
96 default: 95 default:
97 NOTREACHED(); 96 NOTREACHED();
98 continue; // Hope for the best! 97 continue; // Hope for the best!
99 } 98 }
100 } 99 }
101 // fts_read may have returned NULL and set errno to indicate an error. 100 // fts_read may have returned NULL and set errno to indicate an error.
102 if (!error && errno != 0) 101 if (!error && errno != 0)
103 error = errno; 102 error = errno;
104 103
105 if (!fts_close(fts)) { 104 if (!fts_close(fts)) {
106 // If we already have an error, let's use that error instead of the error 105 // If we already have an error, let's use that error instead of the error
107 // fts_close set. 106 // fts_close set.
108 if (!error) 107 if (!error)
109 error = errno; 108 error = errno;
110 } 109 }
111 110
112 if (error) { 111 if (error) {
113 LOG(ERROR) << strerror(error); 112 LOG(ERROR) << strerror(error);
114 return false; 113 return false;
115 } 114 }
116 return true; 115 return true;
117 } 116 }
118 117
119 } // namespace file_util 118 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698