Skip to content

Conversation

brianquinlan
Copy link
Contributor

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

Copy link
Member

@devoncarew devoncarew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts on the PR but nothing blocking.

@@ -24,3 +29,11 @@ base class FileSystem {
throw UnsupportedError('rename');
}
}

FileSystem get fileSystem {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps:

FileSystem get fileSystem => Platform.isWindows ? WindowsFileSystem() : PosixFileSystem();

I assume creating these is cheap?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. These classes have no state.

@@ -27,7 +27,7 @@ void main() {
final path2 = '$tmp/file2';

File(path1).writeAsStringSync('Hello World');
PosixFileSystem().rename(path1, path2);
fileSystem.rename(path1, path2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

above, at the start of main(), perhaps assign the filesystem to a local? final fs = fileSystem;.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why? Are you concerned with performance?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, mostly for documentation purposes in terms of what filesystem is being tested.

@brianquinlan
Copy link
Contributor Author

Sorry, this isn't quite ready for review but I forgot to press the "draft" button.

@brianquinlan brianquinlan marked this pull request as draft March 13, 2025 16:19
@brianquinlan brianquinlan marked this pull request as ready for review March 14, 2025 19:07
@brianquinlan
Copy link
Contributor Author

@devoncarew Do you want to take another look?

// BSD-style license that can be found in the LICENSE file.

export 'src/vm_windows_file_system.dart'
if (dart.library.html) 'src/web_windows_file_system.dart';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious - the web file systems will have differences between the OS platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what API design is right but I want the user to be able to write something like:

bool isHidden(String path) {
  if (fileSystem is WindowsFileSystem) {
    return fileSystem.metadata(path).isHidden;
  } else {
    return path.startsWith(".");
  }
}

Either package:io_file has to protect the web developer from ffi imports or the developer will have to do that themselves (like they do have to with package:http: https://github.com/dart-lang/http/blob/9129a96be871a5779436f042bd13790960171373/pkgs/flutter_http_example/lib/main.dart#L13).

@@ -27,7 +27,7 @@ void main() {
final path2 = '$tmp/file2';

File(path1).writeAsStringSync('Hello World');
PosixFileSystem().rename(path1, path2);
fileSystem.rename(path1, path2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, mostly for documentation purposes in terms of what filesystem is being tested.

Comment on lines 74 to 75
oldPath.toNativeUtf16(),
newPath.toNativeUtf16(),
Copy link

@halildurmus halildurmus Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The memory allocated for these two paths must be freed manually or by wrapping this function's body with using and passing arena as the allocator argument in toNativeUtf16:

void rename(String oldPath, String newPath) {
  using((arena) {
    // ...
    if (win32.MoveFileEx(
          oldPath.toNativeUtf16(allocator: arena),
          newPath.toNativeUtf16(allocator: arena),
    // ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, and great drive by code review! Do you want to review more windows file system code?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, and great drive by code review!

Thanks!

Do you want to review more windows file system code?

Sure! Feel free to send review requests in future PRs. I'd be happy to review them.

@brianquinlan brianquinlan merged commit a36923b into dart-lang:main Mar 17, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants