Class FS_POSIX


  • public class FS_POSIX
    extends FS
    Base FS for POSIX based systems
    Since:
    3.0
    • Constructor Detail

      • FS_POSIX

        protected FS_POSIX()
        Default constructor.
      • FS_POSIX

        protected FS_POSIX​(FS src)
        Constructor
        Parameters:
        src - FS to copy some settings from
    • Method Detail

      • newInstance

        public FS newInstance()
        Create a new instance of the same type of FS.
        Specified by:
        newInstance in class FS
        Returns:
        a new instance of the same type of FS.
      • setUmask

        public void setUmask​(int umask)
        Set the umask, overriding any value observed from the shell.
        Parameters:
        umask - mask to apply when creating files.
        Since:
        4.0
      • discoverGitExe

        protected File discoverGitExe()
        Discover the path to the Git executable.
        Specified by:
        discoverGitExe in class FS
        Returns:
        the path to the Git executable or null if it cannot be determined.
      • isCaseSensitive

        public boolean isCaseSensitive()
        Is this file system case sensitive
        Specified by:
        isCaseSensitive in class FS
        Returns:
        true if this implementation is case sensitive
      • supportsExecute

        public boolean supportsExecute()
        Does this operating system and JRE support the execute flag on files?
        Specified by:
        supportsExecute in class FS
        Returns:
        true if this implementation can provide reasonably accurate executable bit information; false otherwise.
      • canExecute

        public boolean canExecute​(File f)
        Determine if the file is executable (or not).

        Not all platforms and JREs support executable flags on files. If the feature is unsupported this method will always return false.

        If the platform supports symbolic links and f is a symbolic link this method returns false, rather than the state of the executable flags on the target file.

        Specified by:
        canExecute in class FS
        Parameters:
        f - abstract path to test.
        Returns:
        true if the file is believed to be executable by the user.
      • setExecute

        public boolean setExecute​(File f,
                                  boolean canExecute)
        Set a file to be executable by the user.

        Not all platforms and JREs support executable flags on files. If the feature is unsupported this method will always return false and no changes will be made to the file specified.

        Specified by:
        setExecute in class FS
        Parameters:
        f - path to modify the executable status of.
        canExecute - true to enable execution; false to disable it.
        Returns:
        true if the change succeeded; false otherwise.
      • runInShell

        public ProcessBuilder runInShell​(String cmd,
                                         String[] args)
        Initialize a ProcessBuilder to run a command using the system shell.
        Specified by:
        runInShell in class FS
        Parameters:
        cmd - command to execute. This string should originate from the end-user, and thus is platform specific.
        args - arguments to pass to command. These should be protected from shell evaluation.
        Returns:
        a partially completed process builder. Caller should finish populating directory, environment, and then start the process.
      • runHookIfPresent

        public ProcessResult runHookIfPresent​(Repository repository,
                                              String hookName,
                                              String[] args,
                                              OutputStream outRedirect,
                                              OutputStream errRedirect,
                                              String stdinArgs)
                                       throws JGitInternalException
        Checks whether the given hook is defined for the given repository, then runs it with the given arguments.
        Overrides:
        runHookIfPresent in class FS
        Parameters:
        repository - The repository for which a hook should be run.
        hookName - The name of the hook to be executed.
        args - Arguments to pass to this hook. Cannot be null, but can be an empty array.
        outRedirect - A print stream on which to redirect the hook's stdout. Can be null, in which case the hook's standard output will be lost.
        errRedirect - A print stream on which to redirect the hook's stderr. Can be null, in which case the hook's standard error will be lost.
        stdinArgs - A string to pass on to the standard input of the hook. May be null.
        Returns:
        The ProcessResult describing this hook's execution.
        Throws:
        JGitInternalException - if we fail to run the hook somehow. Causes may include an interrupted process or I/O errors.
      • retryFailedLockFileCommit

        public boolean retryFailedLockFileCommit()
        Does this file system have problems with atomic renames?
        Specified by:
        retryFailedLockFileCommit in class FS
        Returns:
        true if the caller should retry a failed rename of a lock file.
      • setHidden

        public void setHidden​(File path,
                              boolean hidden)
                       throws IOException
        Set the hidden attribute for file whose name starts with a period.
        Overrides:
        setHidden in class FS
        Parameters:
        path - a File object.
        hidden - whether to set the file hidden
        Throws:
        IOException
      • getAttributes

        public FS.Attributes getAttributes​(File path)
        Get the file attributes we care for.
        Overrides:
        getAttributes in class FS
        Parameters:
        path - a File object.
        Returns:
        the file attributes we care for.
      • normalize

        public File normalize​(File file)
        Normalize the unicode path to composed form.
        Overrides:
        normalize in class FS
        Parameters:
        file - a File object.
        Returns:
        NFC-format File
      • normalize

        public String normalize​(String name)
        Normalize the unicode path to composed form.
        Overrides:
        normalize in class FS
        Parameters:
        name - path name
        Returns:
        NFC-format string
      • supportsAtomicCreateNewFile

        public boolean supportsAtomicCreateNewFile()
        Does this file system support atomic file creation via java.io.File#createNewFile()? In certain environments (e.g. on NFS) it is not guaranteed that when two file system clients run createNewFile() in parallel only one will succeed. In such cases both clients may think they created a new file.
        Overrides:
        supportsAtomicCreateNewFile in class FS
        Returns:
        true if this implementation support atomic creation of new Files by File.createNewFile()
      • createNewFileAtomic

        public FS.LockToken createNewFileAtomic​(File file)
                                         throws IOException
        Create a new file. See File.createNewFile(). Subclasses of this class may take care to provide a safe implementation for this even if FS.supportsAtomicCreateNewFile() is false

        An implementation of the File#createNewFile() semantics which can create a unique file atomically also on NFS. If the config option core.supportsAtomicCreateNewFile = true (which is the default) then simply Files#createFile() is called. But if core.supportsAtomicCreateNewFile = false then after successful creation of the lock file a hard link to that lock file is created and the attribute nlink of the lock file is checked to be 2. If multiple clients manage to create the same lock file nlink would be greater than 2 showing the error. The hard link needs to be retained until the corresponding file is no longer needed in order to prevent that another process can create the same file concurrently using another NFS client which might not yet see the file due to caching.

        Overrides:
        createNewFileAtomic in class FS
        Parameters:
        file - the unique file to be created atomically
        Returns:
        LockToken this lock token must be held until the file is no longer needed
        Throws:
        IOException
        Since:
        5.0
        See Also:
        "https://www.time-travellers.org/shane/papers/NFS_considered_harmful.html"