Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8272926

Request API to create temporary file/directory in anticipation of renaming to a target location

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • core-libs
    • None

      It is common practice to safely create/replace a file/directory by first creating the file/directory in a temporary location and then renaming it to the target location (ideally with an atomic rename). To use this technique, the temporary location should be constrained so that atomic rename will work. Typically that means being in the same file system volume as the ultimate destination.

      The only option currently available in Java is to create the temporary file/directory in the parent directory of the ultimate destination. Some operating systems provide multiple temporary directories specifically for this use. Using a system provided temporary directory can ensure the security of the temporary file/directory and its eventual deletion.

      This request is to provide an API that can use such a feature where available. (It can fall back to creating the file/directory in the parent where unavailable.)

      For example:
      createTempFileForTarget(target file path, attribute...)
      createTempDirectoryForTarget(target directory path, attribute...)

      On macOS, the FileManager can be used to identify the temporary directory most appropriate for a given target.

      https://developer.apple.com/documentation/foundation/nsfilemanager/1407693-urlfordirectory?language=objc

            Unassigned Unassigned
            alans Alan Snyder
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: