File tree Expand file tree Collapse file tree 7 files changed +43
-0
lines changed Expand file tree Collapse file tree 7 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ class ChrootFileSystem extends FileSystem {
3434 final FileSystem delegate;
3535 final String root;
3636
37+ String _systemTemp;
3738 String _cwd;
3839
3940 /// Creates a new `ChrootFileSystem` backed by the specified [delegate] file
@@ -62,6 +63,15 @@ class ChrootFileSystem extends FileSystem {
6263 @override
6364 Link link (path) => new _ChrootLink (this , common.getPath (path));
6465
66+ /// Gets the system temp directory. This directory will be created on-demand
67+ /// in the local root of the file system. Once created, its location is fixed
68+ /// for the life of the process.
69+ @override
70+ Directory get systemTempDirectory {
71+ _systemTemp ?? = directory (_localRoot).createTempSync ('.tmp_' ).path;
72+ return directory (_systemTemp)..createSync ();
73+ }
74+
6575 /// Gets the current working directory for this file system. Note that this
6676 /// does *not* proxy to the underlying file system's current directory in
6777 /// any way; the state of this file system's current directory is local to
Original file line number Diff line number Diff line change @@ -17,6 +17,13 @@ class LocalFileSystem extends FileSystem {
1717 @override
1818 Link link (path) => new _LocalLink (this , shim.newLink (path));
1919
20+ /// Gets the directory provided by the operating system for creating temporary
21+ /// files and directories in. The location of the system temp directory is
22+ /// platform-dependent, and may be set by an environment variable.
23+ @override
24+ Directory get systemTempDirectory =>
25+ new _LocalDirectory (this , shim.systemTemp ());
26+
2027 @override
2128 Directory get currentDirectory => directory (shim.currentDirectory.path);
2229
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ typedef _Node _SegmentVisitor(
4444/// as [#28078] (https://github.com/dart-lang/sdk/issues/28078) is resolved.
4545class MemoryFileSystem extends FileSystem {
4646 _RootNode _root;
47+ String _systemTemp;
4748 String _cwd = _separator;
4849
4950 MemoryFileSystem () {
@@ -59,6 +60,15 @@ class MemoryFileSystem extends FileSystem {
5960 @override
6061 Link link (path) => new _MemoryLink (this , common.getPath (path));
6162
63+ /// Gets the system temp directory. This directory will be created on-demand
64+ /// in the root of the file system. Once created, its location is fixed for
65+ /// the life of the process.
66+ @override
67+ Directory get systemTempDirectory {
68+ _systemTemp ?? = directory (_separator).createTempSync ('.tmp_' ).path;
69+ return directory (_systemTemp)..createSync ();
70+ }
71+
6272 @override
6373 Directory get currentDirectory => directory (_cwd);
6474
Original file line number Diff line number Diff line change @@ -24,6 +24,12 @@ abstract class FileSystem {
2424 /// [path] can be either a [`String`] , a [`Uri`] , or a [`FileSystemEntity`] .
2525 Link link (path);
2626
27+ /// Gets the system temp directory.
28+ ///
29+ /// It is left to file system implementations to decide how to define the
30+ /// "system temp directory".
31+ Directory get systemTempDirectory;
32+
2733 /// Creates a directory object pointing to the current working directory.
2834 Directory get currentDirectory;
2935
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import 'package:file/src/common.dart' as common;
77io.Directory newDirectory (path) => new io.Directory (common.getPath (path));
88io.File newFile (path) => new io.File (common.getPath (path));
99io.Link newLink (path) => new io.Link (common.getPath (path));
10+ io.Directory systemTemp () => io.Directory .systemTemp;
1011io.Directory get currentDirectory => io.Directory .current;
1112set currentDirectory (dynamic path) => io.Directory .current = path;
1213Future <io.FileStat > stat (String path) => io.FileStat .stat (path);
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ dynamic _requiresIO() => throw new UnsupportedError(_requiresIOMsg);
88io.Directory newDirectory (_) => _requiresIO ();
99io.File newFile (_) => _requiresIO ();
1010io.Link newLink (_) => _requiresIO ();
11+ io.Directory systemTemp () => _requiresIO ();
1112io.Directory get currentDirectory => _requiresIO ();
1213set currentDirectory (dynamic _) => _requiresIO ();
1314Future <io.FileStat > stat (String _) => _requiresIO ();
Original file line number Diff line number Diff line change @@ -120,6 +120,14 @@ void runCommonTests(
120120 });
121121 });
122122
123+ group ('systemTempDirectory' , () {
124+ test ('existsAsDirectory' , () {
125+ var tmp = fs.systemTempDirectory;
126+ expect (tmp, isDirectory);
127+ expect (tmp.existsSync (), isTrue);
128+ });
129+ });
130+
123131 group ('currentDirectory' , () {
124132 test ('defaultsToRoot' , () {
125133 expect (fs.currentDirectory.path, root);
You can’t perform that action at this time.
0 commit comments