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

Side by Side Diff: base/file_util.cc

Issue 3404018: Add a TouchFile function that operates on FilePaths + fixing a bug... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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.h ('k') | base/file_util_posix.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/file_util.h" 5 #include "base/file_util.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <io.h> 8 #include <io.h>
9 #endif 9 #endif
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 193 }
194 194
195 bool IsDot(const FilePath& path) { 195 bool IsDot(const FilePath& path) {
196 return FILE_PATH_LITERAL(".") == path.BaseName().value(); 196 return FILE_PATH_LITERAL(".") == path.BaseName().value();
197 } 197 }
198 198
199 bool IsDotDot(const FilePath& path) { 199 bool IsDotDot(const FilePath& path) {
200 return FILE_PATH_LITERAL("..") == path.BaseName().value(); 200 return FILE_PATH_LITERAL("..") == path.BaseName().value();
201 } 201 }
202 202
203 bool TouchFile(const FilePath& path,
204 const base::Time& last_accessed,
205 const base::Time& last_modified) {
206 base::PlatformFile file =
207 base::CreatePlatformFile(path,
208 base::PLATFORM_FILE_OPEN |
209 base::PLATFORM_FILE_WRITE_ATTRIBUTES,
210 NULL, NULL);
211 if (file != base::kInvalidPlatformFileValue) {
212 bool result = base::TouchPlatformFile(file, last_accessed, last_modified);
213 base::ClosePlatformFile(file);
214 return result;
215 }
216
217 return false;
218 }
219
220 bool SetLastModifiedTime(const FilePath& path,
221 const base::Time& last_modified) {
222 return TouchFile(path, last_modified, last_modified);
223 }
224
203 bool CloseFile(FILE* file) { 225 bool CloseFile(FILE* file) {
204 if (file == NULL) 226 if (file == NULL)
205 return true; 227 return true;
206 return fclose(file) == 0; 228 return fclose(file) == 0;
207 } 229 }
208 230
209 bool TruncateFile(FILE* file) { 231 bool TruncateFile(FILE* file) {
210 if (file == NULL) 232 if (file == NULL)
211 return false; 233 return false;
212 long current_offset = ftell(file); 234 long current_offset = ftell(file);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 // FileEnumerator 420 // FileEnumerator
399 // 421 //
400 // Note: the main logic is in file_util_<platform>.cc 422 // Note: the main logic is in file_util_<platform>.cc
401 423
402 bool FileEnumerator::ShouldSkip(const FilePath& path) { 424 bool FileEnumerator::ShouldSkip(const FilePath& path) {
403 FilePath::StringType basename = path.BaseName().value(); 425 FilePath::StringType basename = path.BaseName().value();
404 return IsDot(path) || (IsDotDot(path) && !(INCLUDE_DOT_DOT & file_type_)); 426 return IsDot(path) || (IsDotDot(path) && !(INCLUDE_DOT_DOT & file_type_));
405 } 427 }
406 428
407 } // namespace 429 } // namespace
OLDNEW
« no previous file with comments | « base/file_util.h ('k') | base/file_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698