Skip to content

Commit

Permalink
file: enable and fix latest team lints
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo committed Dec 12, 2024
1 parent 42effa6 commit 0314343
Show file tree
Hide file tree
Showing 49 changed files with 524 additions and 526 deletions.
7 changes: 1 addition & 6 deletions pkgs/file/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
include: package:lints/recommended.yaml

analyzer:
errors:
# Allow having TODOs in the code
todo: ignore
include: package:dart_flutter_team_lints/analysis_options.yaml
4 changes: 2 additions & 2 deletions pkgs/file/example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import 'package:file/memory.dart';

Future<void> main() async {
final FileSystem fs = MemoryFileSystem();
final Directory tmp = await fs.systemTempDirectory.createTemp('example_');
final File outputFile = tmp.childFile('output');
final tmp = await fs.systemTempDirectory.createTemp('example_');
final outputFile = tmp.childFile('output');
await outputFile.writeAsString('Hello world!');
print(outputFile.readAsStringSync());
}
2 changes: 2 additions & 0 deletions pkgs/file/lib/chroot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

/// A file system that provides a view into _another_ `FileSystem` via a path.
library;

export 'src/backends/chroot.dart';
2 changes: 2 additions & 0 deletions pkgs/file/lib/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

/// Core interfaces containing the abstract `FileSystem` interface definition
/// and all associated types used by `FileSystem`.
library;

export 'src/forwarding.dart';
export 'src/interface.dart';
2 changes: 2 additions & 0 deletions pkgs/file/lib/local.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

/// A local file system implementation. This relies on the use of `dart:io`
/// and is thus not suitable for use in the browser.
library;

export 'src/backends/local.dart';
2 changes: 2 additions & 0 deletions pkgs/file/lib/memory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

/// An implementation of `FileSystem` that exists entirely in memory with an
/// internal representation loosely based on the Filesystem Hierarchy Standard.
library;

export 'src/backends/memory.dart';
export 'src/backends/memory/operations.dart';
9 changes: 4 additions & 5 deletions pkgs/file/lib/src/backends/chroot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library file.src.backends.chroot;

import 'dart:convert';
import 'dart:typed_data';

import 'package:file/file.dart';
import 'package:file/src/common.dart' as common;
import 'package:file/src/io.dart' as io;
import 'package:path/path.dart' as p;

import '../../file.dart';
import '../common.dart' as common;
import '../io.dart' as io;

part 'chroot/chroot_directory.dart';
part 'chroot/chroot_file.dart';
part 'chroot/chroot_file_system.dart';
Expand Down
46 changes: 22 additions & 24 deletions pkgs/file/lib/src/backends/chroot/chroot_directory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

part of file.src.backends.chroot;
part of '../chroot.dart';

class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
with ForwardingDirectory<Directory>, common.DirectoryAddOnsMixin {
_ChrootDirectory(ChrootFileSystem fs, String path) : super(fs, path);
_ChrootDirectory(super.fs, super.path);

factory _ChrootDirectory.wrapped(
ChrootFileSystem fs,
Directory delegate, {
bool relative = false,
}) {
String localPath = fs._local(delegate.path, relative: relative);
var localPath = fs._local(delegate.path, relative: relative);
return _ChrootDirectory(fs, localPath);
}

Expand All @@ -32,7 +32,7 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
if (await fileSystem.type(path) != expectedType) {
throw common.notADirectory(path);
}
FileSystemEntityType type = await fileSystem.type(newPath);
var type = await fileSystem.type(newPath);
if (type != FileSystemEntityType.notFound) {
if (type != expectedType) {
throw common.notADirectory(newPath);
Expand All @@ -44,7 +44,7 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
throw common.directoryNotEmpty(newPath);
}
}
String target = await fileSystem.link(path).target();
var target = await fileSystem.link(path).target();
await fileSystem.link(path).delete();
await fileSystem.link(newPath).create(target);
return fileSystem.directory(newPath);
Expand All @@ -60,7 +60,7 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
if (fileSystem.typeSync(path) != expectedType) {
throw common.notADirectory(path);
}
FileSystemEntityType type = fileSystem.typeSync(newPath);
var type = fileSystem.typeSync(newPath);
if (type != FileSystemEntityType.notFound) {
if (type != expectedType) {
throw common.notADirectory(newPath);
Expand All @@ -72,7 +72,7 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
throw common.directoryNotEmpty(newPath);
}
}
String target = fileSystem.link(path).targetSync();
var target = fileSystem.link(path).targetSync();
fileSystem.link(path).deleteSync();
fileSystem.link(newPath).createSync(target);
return fileSystem.directory(newPath);
Expand All @@ -97,17 +97,15 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
@override
Future<Directory> create({bool recursive = false}) async {
if (_isLink) {
switch (await fileSystem.type(path)) {
case FileSystemEntityType.notFound:
throw common.noSuchFileOrDirectory(path);
case FileSystemEntityType.file:
throw common.fileExists(path);
case FileSystemEntityType.directory:
return switch (await fileSystem.type(path)) {
FileSystemEntityType.notFound =>
throw common.noSuchFileOrDirectory(path),
FileSystemEntityType.file => throw common.fileExists(path),
FileSystemEntityType.directory =>
// Nothing to do.
return this;
default:
throw AssertionError();
}
this,
_ => throw AssertionError()
};
} else {
return wrap(await delegate.create(recursive: recursive));
}
Expand Down Expand Up @@ -137,8 +135,8 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
bool recursive = false,
bool followLinks = true,
}) {
Directory delegate = this.delegate as Directory;
String dirname = delegate.path;
var delegate = this.delegate as Directory;
var dirname = delegate.path;
return delegate
.list(recursive: recursive, followLinks: followLinks)
.map((io.FileSystemEntity entity) => _denormalize(entity, dirname));
Expand All @@ -149,18 +147,18 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
bool recursive = false,
bool followLinks = true,
}) {
Directory delegate = this.delegate as Directory;
String dirname = delegate.path;
var delegate = this.delegate as Directory;
var dirname = delegate.path;
return delegate
.listSync(recursive: recursive, followLinks: followLinks)
.map((io.FileSystemEntity entity) => _denormalize(entity, dirname))
.toList();
}

FileSystemEntity _denormalize(io.FileSystemEntity entity, String dirname) {
p.Context ctx = fileSystem.path;
String relativePart = ctx.relative(entity.path, from: dirname);
String entityPath = ctx.join(path, relativePart);
var ctx = fileSystem.path;
var relativePart = ctx.relative(entity.path, from: dirname);
var entityPath = ctx.join(path, relativePart);
if (entity is io.File) {
return _ChrootFile(fileSystem, entityPath);
} else if (entity is io.Directory) {
Expand Down
10 changes: 5 additions & 5 deletions pkgs/file/lib/src/backends/chroot/chroot_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

part of file.src.backends.chroot;
part of '../chroot.dart';

typedef _SetupCallback = dynamic Function();

class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
with ForwardingFile {
_ChrootFile(ChrootFileSystem fs, String path) : super(fs, path);
_ChrootFile(super.fs, super.path);

factory _ChrootFile.wrapped(
ChrootFileSystem fs,
io.File delegate, {
bool relative = false,
}) {
String localPath = fs._local(delegate.path, relative: relative);
var localPath = fs._local(delegate.path, relative: relative);
return _ChrootFile(fs, localPath);
}

Expand Down Expand Up @@ -126,7 +126,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>

@override
Future<File> create({bool recursive = false, bool exclusive = false}) async {
String path = fileSystem._resolve(
var path = fileSystem._resolve(
this.path,
followLinks: false,
notFound: recursive ? _NotFoundBehavior.mkdir : _NotFoundBehavior.allow,
Expand Down Expand Up @@ -158,7 +158,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>

@override
void createSync({bool recursive = false, bool exclusive = false}) {
String path = fileSystem._resolve(
var path = fileSystem._resolve(
this.path,
followLinks: false,
notFound: recursive ? _NotFoundBehavior.mkdir : _NotFoundBehavior.allow,
Expand Down
22 changes: 11 additions & 11 deletions pkgs/file/lib/src/backends/chroot/chroot_file_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

part of file.src.backends.chroot;
part of '../chroot.dart';

const String _thisDir = '.';
const String _parentDir = '..';
Expand Down Expand Up @@ -107,7 +107,7 @@ class ChrootFileSystem extends FileSystem {
}

value = _resolve(value, notFound: _NotFoundBehavior.throwError);
String realPath = _real(value, resolve: false);
var realPath = _real(value, resolve: false);
switch (delegate.typeSync(realPath, followLinks: false)) {
case FileSystemEntityType.directory:
break;
Expand All @@ -117,7 +117,7 @@ class ChrootFileSystem extends FileSystem {
throw common.notADirectory(path as String);
}
assert(() {
p.Context ctx = delegate.path;
var ctx = delegate.path;
return ctx.isAbsolute(value) && value == ctx.canonicalize(value);
}());
_cwd = value;
Expand Down Expand Up @@ -201,7 +201,7 @@ class ChrootFileSystem extends FileSystem {
throw _ChrootJailException();
}
// TODO(tvolkert): See if _context.relative() works here
String result = realPath.substring(root.length);
var result = realPath.substring(root.length);
if (result.isEmpty) {
result = _localRoot;
}
Expand Down Expand Up @@ -263,8 +263,8 @@ class ChrootFileSystem extends FileSystem {
throw common.noSuchFileOrDirectory(path);
}

p.Context ctx = this.path;
String root = _localRoot;
var ctx = this.path;
var root = _localRoot;
List<String> parts, ledger;
if (ctx.isAbsolute(path)) {
parts = ctx.split(path).sublist(1);
Expand All @@ -277,9 +277,9 @@ class ChrootFileSystem extends FileSystem {
}

String getCurrentPath() => root + ctx.joinAll(ledger);
Set<String> breadcrumbs = <String>{};
var breadcrumbs = <String>{};
while (parts.isNotEmpty) {
String segment = parts.removeAt(0);
var segment = parts.removeAt(0);
if (segment == _thisDir) {
continue;
} else if (segment == _parentDir) {
Expand All @@ -290,8 +290,8 @@ class ChrootFileSystem extends FileSystem {
}

ledger.add(segment);
String currentPath = getCurrentPath();
String realPath = _real(currentPath, resolve: false);
var currentPath = getCurrentPath();
var realPath = _real(currentPath, resolve: false);

switch (delegate.typeSync(realPath, followLinks: false)) {
case FileSystemEntityType.directory:
Expand Down Expand Up @@ -333,7 +333,7 @@ class ChrootFileSystem extends FileSystem {
if (!breadcrumbs.add(currentPath)) {
throw common.tooManyLevelsOfSymbolicLinks(path);
}
String target = delegate.link(realPath).targetSync();
var target = delegate.link(realPath).targetSync();
if (ctx.isAbsolute(target)) {
ledger.clear();
parts.insertAll(0, ctx.split(target).sublist(1));
Expand Down
10 changes: 5 additions & 5 deletions pkgs/file/lib/src/backends/chroot/chroot_file_system_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

part of file.src.backends.chroot;
part of '../chroot.dart';

abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,
D extends io.FileSystemEntity> extends ForwardingFileSystemEntity<T, D> {
Expand Down Expand Up @@ -103,7 +103,7 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,

@override
Future<T> delete({bool recursive = false}) async {
String path = fileSystem._resolve(this.path,
var path = fileSystem._resolve(this.path,
followLinks: false, notFound: _NotFoundBehavior.throwError);

String real(String path) => fileSystem._real(path, resolve: false);
Expand All @@ -114,7 +114,7 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,
if (expectedType == FileSystemEntityType.link) {
await fileSystem.delegate.link(real(path)).delete();
} else {
String resolvedPath = fileSystem._resolve(p.basename(path),
var resolvedPath = fileSystem._resolve(p.basename(path),
from: p.dirname(path), notFound: _NotFoundBehavior.allowAtTail);
if (!recursive && await type(resolvedPath) != expectedType) {
throw expectedType == FileSystemEntityType.file
Expand All @@ -132,7 +132,7 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,

@override
void deleteSync({bool recursive = false}) {
String path = fileSystem._resolve(this.path,
var path = fileSystem._resolve(this.path,
followLinks: false, notFound: _NotFoundBehavior.throwError);

String real(String path) => fileSystem._real(path, resolve: false);
Expand All @@ -143,7 +143,7 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,
if (expectedType == FileSystemEntityType.link) {
fileSystem.delegate.link(real(path)).deleteSync();
} else {
String resolvedPath = fileSystem._resolve(p.basename(path),
var resolvedPath = fileSystem._resolve(p.basename(path),
from: p.dirname(path), notFound: _NotFoundBehavior.allowAtTail);
if (!recursive && type(resolvedPath) != expectedType) {
throw expectedType == FileSystemEntityType.file
Expand Down
6 changes: 3 additions & 3 deletions pkgs/file/lib/src/backends/chroot/chroot_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

part of file.src.backends.chroot;
part of '../chroot.dart';

class _ChrootLink extends _ChrootFileSystemEntity<Link, io.Link>
with ForwardingLink {
_ChrootLink(ChrootFileSystem fs, String path) : super(fs, path);
_ChrootLink(super.fs, super.path);

factory _ChrootLink.wrapped(
ChrootFileSystem fs,
io.Link delegate, {
bool relative = false,
}) {
String localPath = fs._local(delegate.path, relative: relative);
var localPath = fs._local(delegate.path, relative: relative);
return _ChrootLink(fs, localPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

part of file.src.backends.chroot;
part of '../chroot.dart';

class _ChrootRandomAccessFile with ForwardingRandomAccessFile {
_ChrootRandomAccessFile(this.path, this.delegate);
Expand Down
Loading

0 comments on commit 0314343

Please sign in to comment.