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

Side by Side Diff: base/file_util.cc

Issue 100453006: Move Touch to base namespace, remove SetLastModifiedTime. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 166 }
167 167
168 bool GetFileSize(const FilePath& file_path, int64* file_size) { 168 bool GetFileSize(const FilePath& file_path, int64* file_size) {
169 PlatformFileInfo info; 169 PlatformFileInfo info;
170 if (!GetFileInfo(file_path, &info)) 170 if (!GetFileInfo(file_path, &info))
171 return false; 171 return false;
172 *file_size = info.size; 172 *file_size = info.size;
173 return true; 173 return true;
174 } 174 }
175 175
176 bool TouchFile(const FilePath& path,
177 const Time& last_accessed,
178 const Time& last_modified) {
179 int flags = PLATFORM_FILE_OPEN | PLATFORM_FILE_WRITE_ATTRIBUTES;
180
181 #if defined(OS_WIN)
182 // On Windows, FILE_FLAG_BACKUP_SEMANTICS is needed to open a directory.
183 if (DirectoryExists(path))
184 flags |= PLATFORM_FILE_BACKUP_SEMANTICS;
185 #endif // OS_WIN
186
187 const PlatformFile file = CreatePlatformFile(path, flags, NULL, NULL);
188 if (file != kInvalidPlatformFileValue) {
189 bool result = TouchPlatformFile(file, last_accessed, last_modified);
190 ClosePlatformFile(file);
191 return result;
192 }
193
194 return false;
195 }
196
176 } // namespace base 197 } // namespace base
177 198
178 // ----------------------------------------------------------------------------- 199 // -----------------------------------------------------------------------------
179 200
180 namespace file_util { 201 namespace file_util {
181 202
182 using base::FileEnumerator; 203 using base::FileEnumerator;
183 using base::FilePath; 204 using base::FilePath;
184 using base::kMaxUniqueFiles; 205 using base::kMaxUniqueFiles;
185 206
186 bool TouchFile(const FilePath& path,
187 const base::Time& last_accessed,
188 const base::Time& last_modified) {
189 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE_ATTRIBUTES;
190
191 #if defined(OS_WIN)
192 // On Windows, FILE_FLAG_BACKUP_SEMANTICS is needed to open a directory.
193 if (DirectoryExists(path))
194 flags |= base::PLATFORM_FILE_BACKUP_SEMANTICS;
195 #endif // OS_WIN
196
197 const base::PlatformFile file =
198 base::CreatePlatformFile(path, flags, NULL, NULL);
199 if (file != base::kInvalidPlatformFileValue) {
200 bool result = base::TouchPlatformFile(file, last_accessed, last_modified);
201 base::ClosePlatformFile(file);
202 return result;
203 }
204
205 return false;
206 }
207
208 bool SetLastModifiedTime(const FilePath& path,
209 const base::Time& last_modified) {
210 return TouchFile(path, last_modified, last_modified);
211 }
212
213 bool CloseFile(FILE* file) { 207 bool CloseFile(FILE* file) {
214 if (file == NULL) 208 if (file == NULL)
215 return true; 209 return true;
216 return fclose(file) == 0; 210 return fclose(file) == 0;
217 } 211 }
218 212
219 bool TruncateFile(FILE* file) { 213 bool TruncateFile(FILE* file) {
220 if (file == NULL) 214 if (file == NULL)
221 return false; 215 return false;
222 long current_offset = ftell(file); 216 long current_offset = ftell(file);
(...skipping 27 matching lines...) Expand all
250 if (!PathExists(new_path) && 244 if (!PathExists(new_path) &&
251 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) { 245 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) {
252 return count; 246 return count;
253 } 247 }
254 } 248 }
255 249
256 return -1; 250 return -1;
257 } 251 }
258 252
259 } // namespace file_util 253 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util.h ('k') | base/file_util_unittest.cc » ('j') | base/files/file_util_proxy.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698