@@ -341,24 +341,6 @@ final class PosixFileSystem extends FileSystem {
341
341
}
342
342
});
343
343
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
-
362
344
@override
363
345
void createDirectory (String path) => ffi.using ((arena) {
364
346
if (libc.mkdir (
@@ -371,6 +353,22 @@ final class PosixFileSystem extends FileSystem {
371
353
}
372
354
});
373
355
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
+
374
372
@override
375
373
set currentDirectory (String path) => ffi.using ((arena) {
376
374
if (libc.chdir (path.toNativeUtf8 (allocator: arena).cast ()) == - 1 ) {
@@ -389,22 +387,6 @@ final class PosixFileSystem extends FileSystem {
389
387
return buffer.cast< ffi.Utf8 > ().toDartString ();
390
388
});
391
389
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
-
408
390
@override
409
391
PosixMetadata metadata (String path) => ffi.using ((arena) {
410
392
final stat = arena< libc.Stat > ();
@@ -535,24 +517,6 @@ final class PosixFileSystem extends FileSystem {
535
517
);
536
518
});
537
519
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
-
556
520
@override
557
521
Uint8List readAsBytes (String path) => ffi.using ((arena) {
558
522
final fd = _tempFailureRetry (
@@ -637,6 +601,42 @@ final class PosixFileSystem extends FileSystem {
637
601
}
638
602
}
639
603
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
+
640
640
@override
641
641
String get temporaryDirectory => ffi.using ((arena) {
642
642
var env = libc.getenv ('TMPDIR' .toNativeUtf8 (allocator: arena).cast ());
0 commit comments