onepub-dev / dart_posix

MIT License
12 stars 4 forks source link

stat on mac #3

Closed ab36245 closed 2 years ago

ab36245 commented 2 years ago

I've added code to handle stat on both Mac and Linux. It required some restructuring, the stat code is now in a folder to make it more manageable.

I've also added a corresponding lstat function.

I've beefed up the stat_test quite significantly and all stat tests pass on both MacOS and Linux.

Be aware that errno was also broken on MacOS so to get that going I've rejigged the code in unistd/errno.dart.

bsutton commented 2 years ago

test('file', () {

withTempDir((temp) { withTempFile((path) { File(path).writeAsStringSync( '123456789\n' 'This is a\n' 'text file\n' ); 'chmod 4463 $path'.toList(); 'ln $path $temp/test_file_2.txt'.toList();

  'ln $path $temp/test_file_3.txt'.toList();```dart

}); });



S. Brett Sutton
Noojee Contact Solutions
03 8320 8100

On Tue, 7 Dec 2021 at 14:21, ab36245 ***@***.***> wrote:

> ***@***.**** commented on this pull request.
> ------------------------------
>
> In test/src/stat_test.dart
> <https://github.com/noojee/dart_posix/pull/3#discussion_r763598363>:
>
> > -    expect('${struct.size}', equals(size));
> -
> -    expect('${struct.blocks}', equals(blocks));
> -    expect(struct.lastAccess, equals(toDateTime(lastAccess)));
> -    expect(struct.lastModified, equals(toDateTime(lastModified)));
> -    expect(struct.lastStatusChange, equals(toDateTime(lastStatusChange)));
> -
> -    /// we don't check the blocksize as the stat command appears to always
> -    /// report 512 even if the system block size is something else.
> -    /// expect('${struct.blockSize}', equals(blockSize));
> -  });
> +    group('stat:', () {
> +      late final String scratch;
> +
> +      setUpAll(() async {
> +        scratch = _runScript('mytest', 'setup').first;
>
> Is this preferable to an external script?
>
>  test('file', () {
>       final temp = dcli.createTempDir();
>       final path = dcli.join(temp, 'test_file.txt');
>       File(path).writeAsStringSync(
>         '123456789\n'
>         'This is a\n'
>         'text file\n'
>       );
>       'chmod 4463 $path'.toList();
>       'ln $path $temp/test_file_2.txt'.toList();
>       'ln $path $temp/test_file_3.txt'.toList();
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/noojee/dart_posix/pull/3#discussion_r763598363>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAG32OCXDTC6GNKH4YZTYU3UPV4SRANCNFSM5JQBGCRA>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
>
bsutton commented 2 years ago

Yes to all of those except fifo. The posix chmod is exposed in package:dcli/posix.dart as is the reset of the posix commands dcli exports.

If you can create the fifo by shelling out to a process then you can do it from dcli which I can see you have already played with.

'some command'.run; 'some command'.start( with more controls). 'some command'.toList() - which I think you are already using.

'

S. Brett Sutton Noojee Contact Solutions 03 8320 8100

On Tue, 7 Dec 2021 at 13:56, ab36245 @.***> wrote:

@.**** commented on this pull request.

In test/src/stat_test.dart https://github.com/noojee/dart_posix/pull/3#discussion_r763590089:

  • expect('${struct.size}', equals(size));
  • expect('${struct.blocks}', equals(blocks));
  • expect(struct.lastAccess, equals(toDateTime(lastAccess)));
  • expect(struct.lastModified, equals(toDateTime(lastModified)));
  • expect(struct.lastStatusChange, equals(toDateTime(lastStatusChange)));
  • /// we don't check the blocksize as the stat command appears to always
  • /// report 512 even if the system block size is something else.
  • /// expect('${struct.blockSize}', equals(blockSize));
  • });
  • group('stat:', () {
  • late final String scratch;
  • setUpAll(() async {
  • scratch = _runScript('mytest', 'setup').first;

I think dcli looks great and I'm happy to use it. Can I set file permissions (can't see chmod in the methods)? Can I create fifos? If so, I should be able to drop the mytest script.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/noojee/dart_posix/pull/3#discussion_r763590089, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG32OBBIBSGC62FH5FJSDTUPVZUTANCNFSM5JQBGCRA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ab36245 commented 2 years ago

Sounds good. Yes, I've worked out how to run the commands (is toList() the "best" way if I don't want output?), so I'm just putting the finishing touches on the withTempDir/withTempFile approach.

ab36245 commented 2 years ago

BTW, I've added back in your memory corruption test but it is failing. The permissions tests fail. I suspect it is sensitive to umask settings as it expects the file to be 0666 but the ones I get are 0644.

bsutton commented 2 years ago

On my system memory test is passing or did you updated?

bsutton commented 2 years ago

I've published a release which includes your changes. 2.2.3 Greatly appreciate your help!

ab36245 commented 2 years ago

On my system memory test is passing or did you updated?

Sorry, I should have mentioned that I added a simple chmod before entering the loop. All works for me now on both mac and linux