Using a Temporary Directory as a Work Area

An operation can create a private temporary directory to contain files whose names and lifetime belong to one run.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace two independent jobs
  2. Publish only complete results
  3. Give each build its own temporary names
  4. Test cleanup on success and failure

Trace two independent jobs

Both jobs can write output.csv inside separate directories without making the same path mutable. Each can remove its own intermediate files during cleanup. Temporary file ownership motivates that boundary.

Publish only complete results

If one final artifact must remain, verify it and move or copy it under the documented publication rules. See atomic replacement for an operation that uses an appropriate filesystem.[1]

Give each build its own temporary names

Two import jobs can both want to create converted.csv. A separate temporary directory per job avoids name collision and lets both clean up their own files. Preserve only a completed output at its intended destination. See temporary file ownership.

Job A → scratch A
Job B → scratch B
Same output candidate name inside each
Publish under deliberate final identity only after verification

Test cleanup on success and failure

A retained scratch directory can be useful diagnostics if the contract provides a deliberate policy. A normal failed job should not make unrelated work disappear. Test two simultaneous runs and an error after a temporary file was produced.

References

  1. Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau, Operating Systems: Three Easy Pieces ↩