| OLD | NEW |
| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 return NULL; | 159 return NULL; |
| 160 | 160 |
| 161 return CreateAndOpenTemporaryFileInDir(directory, path); | 161 return CreateAndOpenTemporaryFileInDir(directory, path); |
| 162 } | 162 } |
| 163 | 163 |
| 164 bool CreateDirectory(const FilePath& full_path) { | 164 bool CreateDirectory(const FilePath& full_path) { |
| 165 return CreateDirectoryAndGetError(full_path, NULL); | 165 return CreateDirectoryAndGetError(full_path, NULL); |
| 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 File::Info 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, | 176 bool TouchFile(const FilePath& path, |
| 177 const Time& last_accessed, | 177 const Time& last_accessed, |
| 178 const Time& last_modified) { | 178 const Time& last_modified) { |
| 179 int flags = PLATFORM_FILE_OPEN | PLATFORM_FILE_WRITE_ATTRIBUTES; | 179 int flags = File::FLAG_OPEN | File::FLAG_WRITE_ATTRIBUTES; |
| 180 | 180 |
| 181 #if defined(OS_WIN) | 181 #if defined(OS_WIN) |
| 182 // On Windows, FILE_FLAG_BACKUP_SEMANTICS is needed to open a directory. | 182 // On Windows, FILE_FLAG_BACKUP_SEMANTICS is needed to open a directory. |
| 183 if (DirectoryExists(path)) | 183 if (DirectoryExists(path)) |
| 184 flags |= PLATFORM_FILE_BACKUP_SEMANTICS; | 184 flags |= File::FLAG_BACKUP_SEMANTICS; |
| 185 #endif // OS_WIN | 185 #endif // OS_WIN |
| 186 | 186 |
| 187 const PlatformFile file = CreatePlatformFile(path, flags, NULL, NULL); | 187 File file(path, flags); |
| 188 if (file != kInvalidPlatformFileValue) { | 188 if (!file.IsValid()) |
| 189 bool result = TouchPlatformFile(file, last_accessed, last_modified); | 189 return false; |
| 190 ClosePlatformFile(file); | |
| 191 return result; | |
| 192 } | |
| 193 | 190 |
| 194 return false; | 191 return file.SetTimes(last_accessed, last_modified); |
| 195 } | 192 } |
| 196 | 193 |
| 197 bool CloseFile(FILE* file) { | 194 bool CloseFile(FILE* file) { |
| 198 if (file == NULL) | 195 if (file == NULL) |
| 199 return true; | 196 return true; |
| 200 return fclose(file) == 0; | 197 return fclose(file) == 0; |
| 201 } | 198 } |
| 202 | 199 |
| 203 bool TruncateFile(FILE* file) { | 200 bool TruncateFile(FILE* file) { |
| 204 if (file == NULL) | 201 if (file == NULL) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 if (!PathExists(new_path) && | 240 if (!PathExists(new_path) && |
| 244 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) { | 241 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) { |
| 245 return count; | 242 return count; |
| 246 } | 243 } |
| 247 } | 244 } |
| 248 | 245 |
| 249 return -1; | 246 return -1; |
| 250 } | 247 } |
| 251 | 248 |
| 252 } // namespace file_util | 249 } // namespace file_util |
| OLD | NEW |