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

Generation of temporary files in module Filename should be improved #4003

Closed
vicuna opened this issue Apr 12, 2006 · 3 comments
Closed

Generation of temporary files in module Filename should be improved #4003

vicuna opened this issue Apr 12, 2006 · 3 comments

Comments

@vicuna
Copy link

vicuna commented Apr 12, 2006

Original bug ID: 4003
Reporter: @mmottl
Assigned to: @xclerc
Status: closed (set by @xavierleroy on 2011-05-29T10:20:22Z)
Resolution: fixed
Priority: normal
Severity: feature
Version: 3.10+dev
Fixed in version: 3.11.2+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: spiralvoice @mmottl @zoggy

Bug description

Temporary files as generated by "open_temp_file" and "temp_file" are generated in either /tmp (default) or the value of the environment variable "TMPDIR" at startup time. Unfortunately, the temporary directory may be on a different filesystem than the directory where the final file should be moved to. This means that "Sys.rename" will fail (at least on Unix-systems), and even if it worked, it would have to copy the file to the other filesystem, which may take a long time. Since the environment variable is only read at startup, this cannot be changed at runtime, and even if, it would cause problems with threads.

It seems therefore advisable to add functions that perform creation of temporary files in a directory provided at runtime, or using a given filestem.

File attachments

@vicuna
Copy link
Author

vicuna commented Mar 26, 2008

Comment author: spiralvoice

The attached patch updates Filename.temp_file to respect run-time changes to $TMPDIR/$TEMP.

It also adds Filename.temp_dir_name2 (), an updated function to Filename.temp_dir_name, which also respects run-time changes to $TMPDIR/$TEMP.

@vicuna
Copy link
Author

vicuna commented Mar 26, 2008

Comment author: spiralvoice

This code

lprintf_nl "debug1 %s" (Filename.temp_file "blabla" "blub");
lprintf_nl "debug1a %s" (Filename.temp_dir_name);
lprintf_nl "debug1b %s" (Filename.temp_dir_name_2 ());

Unix.putenv "TMPDIR" "/root";

lprintf_nl "debug2 %s" (Filename.temp_file "blabla" "blub");
lprintf_nl "debug2a %s" (Filename.temp_dir_name);
lprintf_nl "debug2b %s" (Filename.temp_dir_name_2 ());

produces these lines with patched Ocaml 3.10.2:

2008/03/26 16:10:41 [cO] debug1 /tmp/blabla0d0cdbblub
2008/03/26 16:10:41 [cO] debug1a /tmp
2008/03/26 16:10:41 [cO] debug1b /tmp
2008/03/26 16:10:41 [cO] debug2 /root/blablaeef4c8blub
2008/03/26 16:10:41 [cO] debug2a /tmp
2008/03/26 16:10:41 [cO] debug2b /root

@vicuna
Copy link
Author

vicuna commented Sep 16, 2009

Comment author: @xclerc

Both Filename.temp_file and Filename.open_temp_file functions now
take an additional optional parameter that is the directory in which the
temporary file should be created.

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

No branches or pull requests

1 participant