ensureFirebaseDebugLogLink function
Ensures that path is a symbolic link to /dev/null.
Links are inspected without following them, so an existing link to
/dev/null is kept as is and the command can be run repeatedly.
Regular files and links to other targets are replaced. Directories are
left untouched and false is returned.
pathが/dev/nullへのシンボリックリンクになるようにします。
リンクをたどらずに判定するため、既に/dev/nullへのリンクがある場合はそのまま維持され、繰り返し実行できます。
通常ファイルや別のリンク先を持つリンクは置き換えます。ディレクトリの場合は何もせずfalseを返します。
Implementation
Future<bool> ensureFirebaseDebugLogLink({
String path = "firebase-debug.log",
}) async {
const target = "/dev/null";
final type = FileSystemEntity.typeSync(path, followLinks: false);
switch (type) {
case FileSystemEntityType.link:
final link = Link(path);
if (link.targetSync() == target) {
return true;
}
await link.delete();
break;
case FileSystemEntityType.directory:
return false;
case FileSystemEntityType.notFound:
break;
default:
await File(path).delete();
break;
}
await Link(path).create(target);
return true;
}