Skip to content

Commit 488cabf

Browse files
authored
Place FileSystem public method in alphabetical order (#266)
1 parent 3a4cff3 commit 488cabf

File tree

3 files changed

+284
-284
lines changed

3 files changed

+284
-284
lines changed

pkgs/io_file/lib/src/file_system.dart

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,19 @@ abstract class FileSystem {
209209
/// ```
210210
String createTemporaryDirectory({String? parent, String? prefix});
211211

212+
/// The current
213+
/// [working directory](https://en.wikipedia.org/wiki/Working_directory) of
214+
/// the Dart process.
215+
///
216+
/// Setting the value of this field will change the working directory for
217+
/// *all* isolates.
218+
///
219+
/// On Windows, unless
220+
/// [long paths are enabled](https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation),
221+
/// the maximum length of the [currentDirectory] path is 260 characters.
222+
String get currentDirectory;
223+
set currentDirectory(String path);
224+
212225
/// TODO(brianquinlan): Add an `exists` method that can determine if a file
213226
/// exists without mutating it on Windows (maybe using `FindFirstFile`?)
214227
@@ -224,19 +237,6 @@ abstract class FileSystem {
224237
/// written to is to attempt to open it.
225238
Metadata metadata(String path);
226239

227-
/// The current
228-
/// [working directory](https://en.wikipedia.org/wiki/Working_directory) of
229-
/// the Dart process.
230-
///
231-
/// Setting the value of this field will change the working directory for
232-
/// *all* isolates.
233-
///
234-
/// On Windows, unless
235-
/// [long paths are enabled](https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation),
236-
/// the maximum length of the [currentDirectory] path is 260 characters.
237-
String get currentDirectory;
238-
set currentDirectory(String path);
239-
240240
/// Deletes the directory at the given path.
241241
///
242242
/// If `path` is a directory but the directory is not empty, then
@@ -256,6 +256,9 @@ abstract class FileSystem {
256256
/// those links are deleted but their targets are not.
257257
void removeDirectoryTree(String path);
258258

259+
/// Reads the entire file contents as a list of bytes.
260+
Uint8List readAsBytes(String path);
261+
259262
/// Renames, and possibly moves a file system object from one path to another.
260263
///
261264
/// If `newPath` is a relative path, it is resolved against the current
@@ -274,9 +277,6 @@ abstract class FileSystem {
274277
/// fails and raises [PathExistsException].
275278
void rename(String oldPath, String newPath);
276279

277-
/// Reads the entire file contents as a list of bytes.
278-
Uint8List readAsBytes(String path);
279-
280280
/// Checks whether two paths refer to the same object in the file system.
281281
///
282282
/// Throws `PathNotFoundException` if either path doesn't exist.

pkgs/io_file/lib/src/vm_posix_file_system.dart

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -341,24 +341,6 @@ final class PosixFileSystem extends FileSystem {
341341
}
342342
});
343343

344-
@override
345-
bool same(String path1, String path2) => ffi.using((arena) {
346-
final stat1 = arena<libc.Stat>();
347-
if (libc.stat(path1.toNativeUtf8(allocator: arena).cast(), stat1) == -1) {
348-
final errno = libc.errno;
349-
throw _getError(errno, systemCall: 'stat', path1: path1);
350-
}
351-
352-
final stat2 = arena<libc.Stat>();
353-
if (libc.stat(path2.toNativeUtf8(allocator: arena).cast(), stat2) == -1) {
354-
final errno = libc.errno;
355-
throw _getError(errno, systemCall: 'stat', path1: path2);
356-
}
357-
358-
return (stat1.ref.st_ino == stat2.ref.st_ino) &&
359-
(stat1.ref.st_dev == stat2.ref.st_dev);
360-
});
361-
362344
@override
363345
void createDirectory(String path) => ffi.using((arena) {
364346
if (libc.mkdir(
@@ -371,6 +353,22 @@ final class PosixFileSystem extends FileSystem {
371353
}
372354
});
373355

356+
@override
357+
String createTemporaryDirectory({String? parent, String? prefix}) =>
358+
ffi.using((arena) {
359+
final directory = parent ?? temporaryDirectory;
360+
final template = p.join(directory, '${prefix ?? ''}XXXXXX');
361+
362+
final path = libc.mkdtemp(
363+
template.toNativeUtf8(allocator: arena).cast(),
364+
);
365+
if (path == nullptr) {
366+
final errno = libc.errno;
367+
throw _getError(errno, systemCall: 'mkdtemp', path1: template);
368+
}
369+
return path.cast<ffi.Utf8>().toDartString();
370+
});
371+
374372
@override
375373
set currentDirectory(String path) => ffi.using((arena) {
376374
if (libc.chdir(path.toNativeUtf8(allocator: arena).cast()) == -1) {
@@ -389,22 +387,6 @@ final class PosixFileSystem extends FileSystem {
389387
return buffer.cast<ffi.Utf8>().toDartString();
390388
});
391389

392-
@override
393-
String createTemporaryDirectory({String? parent, String? prefix}) =>
394-
ffi.using((arena) {
395-
final directory = parent ?? temporaryDirectory;
396-
final template = p.join(directory, '${prefix ?? ''}XXXXXX');
397-
398-
final path = libc.mkdtemp(
399-
template.toNativeUtf8(allocator: arena).cast(),
400-
);
401-
if (path == nullptr) {
402-
final errno = libc.errno;
403-
throw _getError(errno, systemCall: 'mkdtemp', path1: template);
404-
}
405-
return path.cast<ffi.Utf8>().toDartString();
406-
});
407-
408390
@override
409391
PosixMetadata metadata(String path) => ffi.using((arena) {
410392
final stat = arena<libc.Stat>();
@@ -535,24 +517,6 @@ final class PosixFileSystem extends FileSystem {
535517
);
536518
});
537519

538-
@override
539-
void rename(String oldPath, String newPath) => ffi.using((arena) {
540-
// See https://pubs.opengroup.org/onlinepubs/000095399/functions/rename.html
541-
if (libc.rename(
542-
oldPath.toNativeUtf8(allocator: arena).cast(),
543-
newPath.toNativeUtf8(allocator: arena).cast(),
544-
) !=
545-
0) {
546-
final errno = libc.errno;
547-
throw _getError(
548-
errno,
549-
systemCall: 'rename',
550-
path1: oldPath,
551-
path2: newPath,
552-
);
553-
}
554-
});
555-
556520
@override
557521
Uint8List readAsBytes(String path) => ffi.using((arena) {
558522
final fd = _tempFailureRetry(
@@ -637,6 +601,42 @@ final class PosixFileSystem extends FileSystem {
637601
}
638602
}
639603

604+
@override
605+
void rename(String oldPath, String newPath) => ffi.using((arena) {
606+
// See https://pubs.opengroup.org/onlinepubs/000095399/functions/rename.html
607+
if (libc.rename(
608+
oldPath.toNativeUtf8(allocator: arena).cast(),
609+
newPath.toNativeUtf8(allocator: arena).cast(),
610+
) !=
611+
0) {
612+
final errno = libc.errno;
613+
throw _getError(
614+
errno,
615+
systemCall: 'rename',
616+
path1: oldPath,
617+
path2: newPath,
618+
);
619+
}
620+
});
621+
622+
@override
623+
bool same(String path1, String path2) => ffi.using((arena) {
624+
final stat1 = arena<libc.Stat>();
625+
if (libc.stat(path1.toNativeUtf8(allocator: arena).cast(), stat1) == -1) {
626+
final errno = libc.errno;
627+
throw _getError(errno, systemCall: 'stat', path1: path1);
628+
}
629+
630+
final stat2 = arena<libc.Stat>();
631+
if (libc.stat(path2.toNativeUtf8(allocator: arena).cast(), stat2) == -1) {
632+
final errno = libc.errno;
633+
throw _getError(errno, systemCall: 'stat', path1: path2);
634+
}
635+
636+
return (stat1.ref.st_ino == stat2.ref.st_ino) &&
637+
(stat1.ref.st_dev == stat2.ref.st_dev);
638+
});
639+
640640
@override
641641
String get temporaryDirectory => ffi.using((arena) {
642642
var env = libc.getenv('TMPDIR'.toNativeUtf8(allocator: arena).cast());

0 commit comments

Comments
 (0)