Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library index.store.separate_file_mananer; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:io'; | |
| 9 import 'dart:typed_data'; | |
| 10 | |
| 11 import 'package:analysis_server/src/index/store/split_store.dart'; | |
| 12 import 'package:path/path.dart' as pathos; | |
| 13 | |
| 14 | |
| 15 /** | |
| 16 * An implementation of [FileManager] that keeps each file in a separate file | |
| 17 * system file. | |
| 18 */ | |
| 19 class SeparateFileManager implements FileManager { | |
| 20 final Directory _base; | |
| 21 | |
| 22 SeparateFileManager(this._base) { | |
| 23 clear(); | |
| 24 } | |
| 25 | |
| 26 @override | |
| 27 void clear() { | |
| 28 List<FileSystemEntity> entries = _base.listSync(); | |
| 29 for (FileSystemEntity entry in entries) { | |
| 30 entry.deleteSync(recursive: true); | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 @override | |
| 35 void delete(String name) { | |
| 36 File file = _getFile(name); | |
| 37 if (file.existsSync()) { | |
| 38 file.deleteSync(); | |
|
Brian Wilkerson
2014/06/23 19:52:32
Is it a problem to call deleteSync for a file that
scheglov
2014/06/23 20:00:22
Done.
| |
| 39 } | |
| 40 } | |
| 41 | |
| 42 @override | |
| 43 Future<List<int>> read(String name) { | |
| 44 File file = _getFile(name); | |
| 45 return file.exists().then((bool exists) { | |
| 46 if (!exists) { | |
| 47 return null; | |
| 48 } | |
| 49 return file.readAsBytes(); | |
|
Brian Wilkerson
2014/06/23 19:52:32
Similar question. If readAsBytes throws an excepti
scheglov
2014/06/23 20:00:22
Done.
| |
| 50 }); | |
| 51 } | |
| 52 | |
| 53 @override | |
| 54 Future write(String name, List<int> bytes) { | |
| 55 return _getFile(name).writeAsBytes(bytes); | |
| 56 } | |
| 57 | |
| 58 File _getFile(String name) { | |
| 59 String path = pathos.join(_base.path, name); | |
| 60 return new File(path); | |
| 61 } | |
| 62 } | |
| OLD | NEW |