Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[flutter_tools] temporary directory (#105815)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasguerrero committed Jun 17, 2022
1 parent b1b1ee9 commit fae31ee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/flutter_tools/lib/src/base/file_system.dart
Expand Up @@ -6,6 +6,7 @@ import 'package:file/file.dart';
import 'package:file/local.dart' as local_fs;
import 'package:meta/meta.dart';

import 'common.dart';
import 'io.dart';
import 'platform.dart';
import 'process.dart';
Expand Down Expand Up @@ -218,7 +219,12 @@ class LocalFileSystem extends local_fs.LocalFileSystem {
@override
Directory get systemTempDirectory {
if (_systemTemp == null) {
_systemTemp = super.systemTempDirectory.createTempSync('flutter_tools.')
if (!superSystemTempDirectory.existsSync()) {
throwToolExit('Your system temp directory (${superSystemTempDirectory.path}) does not exist. '
'Did you set an invalid override in your environment? See issue https://github.com/flutter/flutter/issues/74042 for more context.'
);
}
_systemTemp = superSystemTempDirectory.createTempSync('flutter_tools.')
..createSync(recursive: true);
// Make sure that the temporary directory is cleaned up if the tool is
// killed by a signal.
Expand All @@ -239,4 +245,8 @@ class LocalFileSystem extends local_fs.LocalFileSystem {
}
return _systemTemp!;
}

// This only exist because the memory file system does not support a systemTemp that does not exists #74042
@visibleForTesting
Directory get superSystemTempDirectory => super.systemTempDirectory;
}
Expand Up @@ -7,6 +7,7 @@ import 'dart:io' as io;

import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/platform.dart';
Expand All @@ -15,6 +16,13 @@ import 'package:test/fake.dart';

import '../../src/common.dart';

class LocalFileSystemFake extends LocalFileSystem {
LocalFileSystemFake.test({required super.signals}) : super.test();

@override
Directory get superSystemTempDirectory => directory('/does_not_exist');
}

void main() {
group('fsUtils', () {
late MemoryFileSystem fs;
Expand Down Expand Up @@ -174,6 +182,23 @@ void main() {

expect(temp.existsSync(), isFalse);
});

testWithoutContext('throwToolExit when temp not found', () async {
final Signals signals = Signals.test();
final LocalFileSystemFake localFileSystem = LocalFileSystemFake.test(
signals: signals,
);

try {
localFileSystem.systemTempDirectory;
fail('expected tool exit');
} on ToolExit catch(e) {
expect(e.message, 'Your system temp directory (/does_not_exist) does not exist. '
'Did you set an invalid override in your environment? '
'See issue https://github.com/flutter/flutter/issues/74042 for more context.'
);
}
});
});
}

Expand Down

0 comments on commit fae31ee

Please sign in to comment.