Skip to content

Conversation

@tobil4sk
Copy link
Member

@tobil4sk tobil4sk commented Feb 6, 2026

The pwrite() function shall be equivalent to write(), except that it writes into a given position and does not change the file offset (regardless of whether O_APPEND is set)

According to the posix standard, when using pwrite (in our case, passing
this.pos to writeSync), the O_APPEND flag is ignored.

Linux doesn't comply with this, by Mac does, so we have to make the code
compatible by passing null as the position which means write will be
used instead of pwrite.

See:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/pwrite.html

> The pwrite() function shall be equivalent to write(), except that it
> writes into a given position and does not change the file offset
> (regardless of whether O_APPEND is set)

Regarding linux bug:
https://man7.org/linux/man-pages/man2/pread.2.html#BUGS
This reverts commit 7c4f984.

Haxe's `deleteDirectory` documentation specifies that only empty
directories can be deleted, which this does not comply with.

> Only empty directories can be deleted.

`deleteDirectory` is also specified to throw if the file does not exist,
which also didn't happen with this implementation.

> if that directory cannot be deleted, an exception is thrown.

See: https://api.haxe.org/sys/FileSystem.html
This is specified by haxe and other targets also do this.
@Simn
Copy link
Member

Simn commented Feb 7, 2026

I would prefer if we changed the deleteDirectory specification to support recursion on all targets. It's one of these annoying API specifications that gets in the way of the user's clear intent, and it forces custom implementations of a version that does support recursion in many places.

@tobil4sk
Copy link
Member Author

tobil4sk commented Feb 7, 2026

This was discussed in HaxeFoundation/haxe#5585, but was forgotten about and closed.

it forces custom implementations of a version that does support recursion in many places.

From a quick search, I can see python and node seem to be the only ones that support this within their std libraries. On remaining targets it would have to be implemented manually which would requires properly handling symlinks etc. It would not be trivial to write properly with all the proper tests covering it.

I do see why it is useful to have it, but if we do support recursion across targets, it should be opt in because:

  • All target languages do not delete recursively by default, so this is the expectation for most people
  • It would be a breaking change, users might rely on the function throwing if it's non-empty, and if stuff goes wrong data will be lost because deleteDirectory does not put stuff in the recycling bin.

I think hxnodejs should still comply with the current spec and require an empty directory by default. Then we can add an optional recursive: Bool argument here, and re-open that issue to gradually start adding it to other targets?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File.append is wrong in js target with hxnodejs on macOS

2 participants