Skip to content

Commit eda5a8b

Browse files
authored
Add basename and dirname to FileSystemEntity (flutter#15)
1 parent 57a4a6c commit eda5a8b

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

lib/src/backends/chroot/chroot_file_system_entity.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,
1414

1515
_ChrootFileSystemEntity(this.fileSystem, this.path);
1616

17+
@override
18+
String get dirname => fileSystem.path.dirname(path);
19+
20+
@override
21+
String get basename => fileSystem.path.basename(path);
22+
1723
@override
1824
D get delegate => getDelegate();
1925

lib/src/backends/local/local_file_system_entity.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ abstract class _LocalFileSystemEntity<T extends FileSystemEntity,
1414

1515
_LocalFileSystemEntity(this.fileSystem, this.delegate);
1616

17+
@override
18+
String get dirname => fileSystem.path.dirname(path);
19+
20+
@override
21+
String get basename => fileSystem.path.basename(path);
22+
1723
@override
1824
Directory wrapDirectory(io.Directory delegate) =>
1925
new _LocalDirectory(fileSystem, delegate);

lib/src/backends/memory/memory_file_system_entity.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ abstract class _MemoryFileSystemEntity implements FileSystemEntity {
2121

2222
_MemoryFileSystemEntity(this.fileSystem, this.path);
2323

24-
/// Gets the part of this entity's path before the last separator.
24+
@override
2525
String get dirname => fileSystem.path.dirname(path);
2626

27-
/// Gets the part of this entity's path after the last separator.
27+
@override
2828
String get basename => fileSystem.path.basename(path);
2929

3030
/// Returns the expected type of this entity, which may differ from the type

lib/src/forwarding/forwarding_file_system_entity.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,10 @@ abstract class ForwardingFileSystemEntity<T extends FileSystemEntity,
8585

8686
@override
8787
String get path => delegate.path;
88+
89+
@override
90+
String get basename => fileSystem.path.basename(path);
91+
92+
@override
93+
String get dirname => fileSystem.path.dirname(path);
8894
}

lib/src/interface/file_system_entity.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@ abstract class FileSystemEntity implements io.FileSystemEntity {
99
/// Returns the file system responsible for this entity.
1010
FileSystem get fileSystem;
1111

12+
/// Gets the part of this entity's path after the last separator.
13+
///
14+
/// context.basename('path/to/foo.dart'); // -> 'foo.dart'
15+
/// context.basename('path/to'); // -> 'to'
16+
///
17+
/// Trailing separators are ignored.
18+
///
19+
/// context.basename('path/to/'); // -> 'to'
20+
String get basename;
21+
22+
/// Gets the part of this entity's path before the last separator.
23+
///
24+
/// context.dirname('path/to/foo.dart'); // -> 'path/to'
25+
/// context.dirname('path/to'); // -> 'path'
26+
/// context.dirname('foo.dart'); // -> '.'
27+
///
28+
/// Trailing separators are ignored.
29+
///
30+
/// context.dirname('path/to/'); // -> 'path'
31+
String get dirname;
32+
1233
// Override method definitions to codify the return type covariance.
1334
@override
1435
Future<FileSystemEntity> delete({bool recursive: false});

0 commit comments

Comments
 (0)