Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Node local temporary files/dirs
08-07-2017, 05:07 PM (This post was last modified: 08-07-2017 05:09 PM by zma.)
Post: #1
Node local temporary files/dirs
It is common for programs to have some temporary files like for

logging: http://tab.d-thinker.org/showthread.php?tid=8242

tmp dir: http://tab.d-thinker.org/showthread.php?...http://tab.d-thinker.org/showthread.php?tid=8243&pid=4675

These programs should careful choose the names/paths to avoid conflict while there is no guarantee.

Let's use a common convention so that programs can make use and be sure it is free from conflicts with programs following the convention:

For a program named ${progname} executed by user ${USER}, if it want to use a temporary files/dirs, the common way is to use:

/thinker/local/$USER/${progname}/${file_or_dir_name}

where the ${file_or_dir_name} is chosen by the program.

The program is responsible to clean these files after they are not used.

If there may be multiple program instances running and the programs would like to use unique name for each instance, it can use various ways suitable to the program logic. 2 possible choices:

- $(mktemp -p /thinker/local/$USER/${progname}/) to get a unique file
- /thinker/local/$USER/${progname}/${BASHPID} to get a file based on its pid.
Visit this user's website Find all posts by this user
Quote this message in a reply
08-07-2017, 05:10 PM
Post: #2
RE: Node local temporary files/dirs
Ray: please review.
Visit this user's website Find all posts by this user
Quote this message in a reply
08-07-2017, 05:19 PM
Post: #3
RE: Node local temporary files/dirs
(08-07-2017 05:07 PM)zma Wrote:  /thinker/local/$USER/${progname}/${file_or_dir_name}

The program is responsible to clean these files after they are not used.

I think a temp dir under /tmp would be better because some programs may not be able to clear their own tmp files, like filelock.

Under /tmp, the files can be cleared automatically if they are not used for a long time.
Find all posts by this user
Quote this message in a reply
08-07-2017, 05:25 PM
Post: #4
RE: Node local temporary files/dirs
(08-07-2017 05:19 PM)rayluk Wrote:  
(08-07-2017 05:07 PM)zma Wrote:  /thinker/local/$USER/${progname}/${file_or_dir_name}

The program is responsible to clean these files after they are not used.

I think a temp dir under /tmp would be better because some programs may not be able to clear their own tmp files, like filelock.

Under /tmp, the files can be cleared automatically if they are not used for a long time.

Then how shall programs avoid conflicts? /tmp is a system specific dir and many program besides of our ones use it too.

The auto-cleaning feature causes trouble. It cleans files programs don't want them to be cleaned. For files in /tmp that needs to be live longer such as for logs, programs should be configure systemd to avoid cleaning them.

And /tmp is a in-memory fs. All data there consumes memory.

Small files like those used by filelock are fine to be left there if it is small and overwritten next time.
Visit this user's website Find all posts by this user
Quote this message in a reply
08-07-2017, 05:26 PM
Post: #5
RE: Node local temporary files/dirs
(08-07-2017 05:25 PM)zma Wrote:  
(08-07-2017 05:19 PM)rayluk Wrote:  
(08-07-2017 05:07 PM)zma Wrote:  /thinker/local/$USER/${progname}/${file_or_dir_name}

The program is responsible to clean these files after they are not used.

I think a temp dir under /tmp would be better because some programs may not be able to clear their own tmp files, like filelock.

Under /tmp, the files can be cleared automatically if they are not used for a long time.

Then how shall programs avoid conflicts? /tmp is a system specific dir and many program besides of our ones use it too.

The auto-cleaning feature causes trouble. It cleans files programs don't want them to be cleaned. For files in /tmp that needs to be live longer such as for logs, programs should be configure systemd to avoid cleaning them.

And /tmp is a in-memory fs. All data there consumes memory.

Small files like those used by filelock are fine to be left there if it is small and overwritten next time.

Good to me then
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: