java.lang.Object
io.goobi.viewer.model.administration.configeditor.VimSwapFile

public final class VimSwapFile extends Object
Utility für vim-kompatible Swap-Dateien (B0-Block-Format). pid==0 im B0-Block ist der Web-UI-Marker. Vim schreibt immer eine echte PID.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    check(Path file)
    Checks the lock status of file by inspecting its swap file.
    static void
    create(Path file, String hostname)
    Creates a vim-compatible B0-block swap file for file, using pid=0 as the Web-UI marker.
    static void
    create(Path file, String hostname, String sessionId)
    Creates a vim-compatible B0-block swap file with pid=0 (web-UI marker), tagged with an owner token so that only the owning session deletes it again.
    static void
    delete(Path file)
    Deletes the Web-UI swap file for file if it exists and is owned by the Web UI (pid=0).
    static void
    delete(Path file, String sessionId)
    Deletes the web-UI swap file for file only if it is owned by the web UI (pid=0) AND its owner tag matches sessionId.
    static Path
    Returns the path of the vim-style swap file for the given file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getSwapFilePath

      public static Path getSwapFilePath(Path file)
      Returns the path of the vim-style swap file for the given file. The swap file is named .<filename>.swp and located in the same directory as file.
      Parameters:
      file - the file to lock
      Returns:
      the swap file path
    • create

      public static void create(Path file, String hostname) throws IOException
      Creates a vim-compatible B0-block swap file for file, using pid=0 as the Web-UI marker. Vim will recognise the swap file and warn any user who tries to open the file concurrently.
      Parameters:
      file - the file to lock
      hostname - the hostname to embed in the swap file; if null, the local hostname is used
      Throws:
      IOException - if the swap file cannot be written
    • create

      public static void create(Path file, String hostname, String sessionId) throws IOException
      Creates a vim-compatible B0-block swap file with pid=0 (web-UI marker), tagged with an owner token so that only the owning session deletes it again.
      Parameters:
      file - the file to lock
      hostname - hostname to embed; if null, the local hostname is used
      sessionId - owning HTTP session id (tagged as a hash); may be null for an untagged swap file
      Throws:
      IOException - if the swap file cannot be written
    • delete

      public static void delete(Path file)
      Deletes the Web-UI swap file for file if it exists and is owned by the Web UI (pid=0). Swap files owned by a running vim process (non-zero pid) are never deleted. If the swap file cannot be read, a warning is logged and no deletion is attempted.
      Parameters:
      file - the file whose swap file should be removed
    • delete

      public static void delete(Path file, String sessionId)
      Deletes the web-UI swap file for file only if it is owned by the web UI (pid=0) AND its owner tag matches sessionId. A swap file owned by a running vim process or by a different session is left.
      Parameters:
      file - the file whose swap file should be removed
      sessionId - the session that must own the swap file
    • check

      public static VimSwapFile.Status check(Path file)
      Checks the lock status of file by inspecting its swap file. On systems where /proc is unavailable, a non-zero pid is conservatively reported as VimSwapFile.Status.LOCKED_BY_VIM.
      Parameters:
      file - the file to check
      Returns:
      the lock status