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

Do not use the system's tmp dir #56

Merged
merged 2 commits into from
Oct 23, 2023

Conversation

teohhanhui
Copy link
Contributor

(split out from #48)

/cc @issackelly

Renaming a file does not work across filesystems.

co-authored-by: Issac Kelly <[email protected]>
@alexjg
Copy link
Collaborator

alexjg commented Oct 23, 2023

I think it might be worth making this a configuration option. I think the reason for not using the system temp directory is that it might not be on the same filesystem as the data directory and thus atomic renames may not work (correct me if I'm wrong there). I think this is a good argument for not defaulting to the system temp directory. However, if - like me - you want to run this on your primary desktop and your system temp directory is on the same filesystem as the data directory then the temp directory has the really nice feature of cleaning itself up on every reboot and so if the sync server crashes and leaves data hanging around it will not persist beyond the next boot.

@teohhanhui
Copy link
Contributor Author

Extrapolating from there, actually the user could already override the TMPDIR env var (or TMP / TEMP on Windows). So I think there's no need for a config.

I'm closing this.

@teohhanhui teohhanhui closed this Oct 23, 2023
@issackelly
Copy link
Contributor

Alex, you're right about the need, and I don't really care that it's a config option or not.
Unfortunately Han, I think I still need a config option. We can't assume an overwrite TMP for the whole application just for automerge-repo-rs. Some things do not need an atomic move out of TMP and can benefit from ramfs or something. I think that I could probably work around it but a confg variable that defaults to TMPDIR sounds like an "everbody wins!" option

@teohhanhui teohhanhui reopened this Oct 23, 2023
@alexjg
Copy link
Collaborator

alexjg commented Oct 23, 2023

@issackelly I agree, although I don't care too much about defaulting to TMPDIR. I think the data directory itself is a good default (i.e. the least likely to result in bug reports for us 😅 ) but there should be the option to override it to whatever the user wants for people who understand the possible downsides.

@teohhanhui
Copy link
Contributor Author

Not sure if this is okay?

@alexjg
Copy link
Collaborator

alexjg commented Oct 23, 2023

I think the only thing remaining is to add some brief documentation to the with_tmpdir methods explaining what they do (sadly this will have to be duplicated due to the need for duplicate implementations). The most important thing to explain is that the user needs to ensure that the tempdir is on the same filesystem as the data dir.

@teohhanhui teohhanhui force-pushed the fix/dont-use-system-tmp-dir branch from 5e132db to c78738e Compare October 23, 2023 22:14
@teohhanhui teohhanhui force-pushed the fix/dont-use-system-tmp-dir branch from c78738e to 51dae34 Compare October 23, 2023 22:20
@teohhanhui
Copy link
Contributor Author

Docs added.

///
/// This will attempt to create the tmpdir directory and throw an error if
/// it does not exist.
pub fn with_tmpdir<P: AsRef<Path>>(self, tmpdir: P) -> Option<Result<Self, std::io::Error>> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this return type intuitive? None is only returned when we can't take ownership of the inner FsStore...

@alexjg alexjg merged commit 847d0ff into automerge:main Oct 23, 2023
8 checks passed
@teohhanhui teohhanhui deleted the fix/dont-use-system-tmp-dir branch October 23, 2023 22:27
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.

3 participants