-
Notifications
You must be signed in to change notification settings - Fork 5
Add rename
support for Windows
#201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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;
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Sorry, this isn't quite ready for review but I forgot to press the "draft" button. |
@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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
oldPath.toNativeUtf16(), | ||
newPath.toNativeUtf16(), |
There was a problem hiding this comment.
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),
// ...
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.