Skip to content

Ensure no file handles remain open during in-place persist (closes #292).#300

Merged
01mf02 merged 1 commit into01mf02:mainfrom
fgimian:avoid-open-handles-during-persist
Jul 3, 2025
Merged

Ensure no file handles remain open during in-place persist (closes #292).#300
01mf02 merged 1 commit into01mf02:mainfrom
fgimian:avoid-open-handles-during-persist

Conversation

@fgimian
Copy link
Contributor

@fgimian fgimian commented Jul 1, 2025

Hey there, here's the fix for persisting files using the in-place option on Windows. This will ensure that the file handle used for processing of the file will be released before persisting to disk from the temp directory.

See output below:

~\source\jaq on  avoid-open-handles-during-persist [?] via 🦀 v1.88.0 took 3s
🕙 [ 09:48:19 AM ] ❯ git co main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.

~\source\jaq on  main [?] via 🦀 v1.88.0
🕙 [ 09:48:26 AM ] ❯ cp ..\firefox-settings\bookmarks.json .

~\source\jaq on  main [?] via 🦀 v1.88.0
🕙 [ 09:48:31 AM ] ❯ cargo run -- -i . bookmarks.json
   Compiling jaq v2.2.0 (C:\Users\Fots\source\jaq\jaq)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.30s
     Running `target\debug\jaq.exe -i . bookmarks.json`
Error: failed to persist temporary file: Access is denied. (os error 5)
error: process didn't exit successfully: `target\debug\jaq.exe -i . bookmarks.json` (exit code: 2)

~\source\jaq on  main [?] via 🦀 v1.88.0 took 4s
🕙 [ 09:48:38 AM ] ❯ git co avoid-open-handles-during-persist
Switched to branch 'avoid-open-handles-during-persist'
Your branch is up to date with 'origin/avoid-open-handles-during-persist'.

~\source\jaq on  avoid-open-handles-during-persist [?] via 🦀 v1.88.0
🕙 [ 09:48:40 AM ] ❯ cp ..\firefox-settings\bookmarks.json .

~\source\jaq on  avoid-open-handles-during-persist [?] via 🦀 v1.88.0
🕙 [ 09:48:43 AM ] ❯ cargo run -- -i . bookmarks.json
   Compiling jaq v2.2.0 (C:\Users\Fots\source\jaq\jaq)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.20s
     Running `target\debug\jaq.exe -i . bookmarks.json`

Unfortunately, this does lead to a tiny bit of repeated code, but I think this is somewhat unavoidable.

Cheers
Fotis

@fgimian fgimian changed the title Ensure no open file handles during in-place persist (closes #292). Ensure no file handles remain open during in-place persist (closes #292). Jul 2, 2025
@01mf02
Copy link
Owner

01mf02 commented Jul 2, 2025

Hi @fgimian, thanks for diagnosing this problem! I find the code repetition to be a bit problematic, though; wouldn't it suffice to run std::mem::drop(file); just before let perms = ...?

@fgimian
Copy link
Contributor Author

fgimian commented Jul 2, 2025

Hi @fgimian, thanks for diagnosing this problem! I find the code repetition to be a bit problematic, though; wouldn't it suffice to run std::mem::drop(file); just before let perms = ...?

Good idea, I'll give it a try tomorrow and let you know how it goes.

Cheers
Fotis

@fgimian
Copy link
Contributor Author

fgimian commented Jul 3, 2025

@01mf02 Thanks again for your help, I've tested your idea and it indeed does work as expected. I've updated the PR with the change discussed so it should be ready for review again.

Cheers
Fotis

@01mf02 01mf02 merged commit c9d878f into 01mf02:main Jul 3, 2025
3 checks passed
@01mf02
Copy link
Owner

01mf02 commented Jul 3, 2025

Excellent! Thanks for your confirmation and for your help with diagnosing this issue!

@fgimian fgimian deleted the avoid-open-handles-during-persist branch July 16, 2025 01:41
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.

2 participants