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 | |
10 import 'package:analysis_server/src/index/store/split_store.dart'; | |
11 import 'package:path/path.dart' as pathos; | |
12 | |
13 | |
14 /** | |
15 * An implementation of [FileManager] that keeps each file in a separate file | |
16 * system file. | |
17 */ | |
18 class SeparateFileManager implements FileManager { | |
19 final Directory _directory; | |
20 | |
21 SeparateFileManager(this._directory) { | |
22 clear(); | |
23 } | |
24 | |
25 @override | |
26 void clear() { | |
27 List<FileSystemEntity> entries = _directory.listSync(); | |
28 for (FileSystemEntity entry in entries) { | |
29 entry.deleteSync(recursive: true); | |
30 } | |
31 } | |
32 | |
33 @override | |
34 void delete(String name) { | |
35 File file = _getFile(name); | |
36 try { | |
37 file.deleteSync(); | |
38 } catch (e) { | |
39 } | |
40 } | |
41 | |
42 @override | |
43 Future<List<int>> read(String name) { | |
44 File file = _getFile(name); | |
45 return file.readAsBytes().catchError((e) { | |
46 return null; | |
47 }); | |
48 } | |
49 | |
50 @override | |
51 Future write(String name, List<int> bytes) { | |
52 return _getFile(name).writeAsBytes(bytes); | |
53 } | |
54 | |
55 File _getFile(String name) { | |
56 String path = pathos.join(_directory.path, name); | |
57 return new File(path); | |
58 } | |
59 } | |
OLD | NEW |