Skip to content
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

fix(files): Writing new files works across devices #148

Merged
merged 1 commit into from
Oct 19, 2024
Merged

Conversation

alexpovel
Copy link
Owner

persist of tempfile does not work across
device boundaries, so if the device backing the
temporary directory is e.g. tmpfs, then
persist fails. It actually had no useful
benefit, so we can just remove it and write to the destination directly.

Reproduced bug and confirmed fix on a Debian
machine with:

$ sudo mkdir -p /path/to/temp_dir
$ sudo mount -t tmpfs -o size=100m tmpfs /path/to/temp_dir
$ sudo mount | rg 'temp'
tmpfs on /path/to/temp_dir type tmpfs (rw,relatime,size=102400k,inode64)
$ export TMPDIR=/path/to/temp_dir
$ cargo run -- --python class a whatever

TMPDIR env var is respected by tempfile. The
above cargo run fails without this patch. (There is an end-to-end test for file writing, but that
has never failed for some reason... seems like
none of my machines (including Ubuntu 24) or CI
exhibited the issue).

Closes #145

`persist` of `tempfile` does not work across
device boundaries, so if the device backing the
temporary directory is e.g. `tmpfs`, then
`persist` fails. It actually had no useful
benefit, so we can just remove it and write to the
destination directly.

Reproduced bug and confirmed fix on a Debian
machine with:

```console
$ sudo mkdir -p /path/to/temp_dir
$ sudo mount -t tmpfs -o size=100m tmpfs /path/to/temp_dir
$ sudo mount | rg 'temp'
tmpfs on /path/to/temp_dir type tmpfs (rw,relatime,size=102400k,inode64)
$ export TMPDIR=/path/to/temp_dir
$ cargo run -- --python class a whatever
```

`TMPDIR` env var is respected by `tempfile`. The
above `cargo run` fails without this patch. (There
is an end-to-end test for file writing, but that
has never failed for some reason... seems like
none of my machines (including Ubuntu 24) or CI
exhibited the issue).

Closes #145
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.69%. Comparing base (3b8abfa) to head (b238e31).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #148      +/-   ##
==========================================
+ Coverage   86.58%   86.69%   +0.11%     
==========================================
  Files          32       32              
  Lines        1975     1969       -6     
==========================================
- Hits         1710     1707       -3     
+ Misses        265      262       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alexpovel
Copy link
Owner Author

Very hard to reproduce. Even cargo test with a modified TMPDIR doesn't reproduce it. There are tests for it:

fn test_cli_files(

and I can confirm they also respect and use TMPDIR (export TMPDIR=...), reading and writing to a directory on a different device (tmpfs), but not triggering the failure. Only manual cargo run does. This suggests the tests are faulty but wasn't able to track that down.

@alexpovel alexpovel merged commit 1b27825 into main Oct 19, 2024
17 checks passed
@alexpovel alexpovel deleted the tempfile-fix branch October 27, 2024 09:34
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.

Replacement results in "Invalid cross-device link"
2 participants