Class FS_POSIX
- java.lang.Object
-
- org.eclipse.jgit.util.FS
-
- org.eclipse.jgit.util.FS_POSIX
-
public class FS_POSIX extends FS
Base FS for POSIX based systems- Since:
- 3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classFS_POSIX.AtomicFileCreation-
Nested classes/interfaces inherited from class org.eclipse.jgit.util.FS
FS.Attributes, FS.ExecutionResult, FS.FileStoreAttributes, FS.FSFactory, FS.LockToken
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.nio.file.FileStore,java.lang.Boolean>CAN_HARD_LINKprivate static java.lang.StringDEFAULT_GIT_LOCATIONprivate static intDEFAULT_UMASKprivate static org.slf4j.LoggerLOGprivate FS_POSIX.AtomicFileCreationsupportsAtomicFileCreationprivate intumask-
Fields inherited from class org.eclipse.jgit.util.FS
DETECTED, NO_ENTRIES
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private static voidapply(java.util.Set<java.nio.file.attribute.PosixFilePermission> set, int umask, java.nio.file.attribute.PosixFilePermission perm, int test)booleancanExecute(java.io.File f)Determine if the file is executable (or not).booleancreateNewFile(java.io.File lock)Deprecated.FS.LockTokencreateNewFileAtomic(java.io.File file)Create a new file.protected java.io.FilediscoverGitExe()Discover the path to the Git executable.FS.AttributesgetAttributes(java.io.File path)Get the file attributes we care for.booleanisCaseSensitive()Is this file system case sensitiveFSnewInstance()Create a new instance of the same type of FS.java.io.Filenormalize(java.io.File file)Normalize the unicode path to composed form.java.lang.Stringnormalize(java.lang.String name)Normalize the unicode path to composed form.private static intreadUmask()booleanretryFailedLockFileCommit()Does this file system have problems with atomic renames?ProcessResultrunHookIfPresent(Repository repository, java.lang.String hookName, java.lang.String[] args, java.io.OutputStream outRedirect, java.io.OutputStream errRedirect, java.lang.String stdinArgs)Checks whether the given hook is defined for the given repository, then runs it with the given arguments.java.lang.ProcessBuilderrunInShell(java.lang.String cmd, java.lang.String[] args)Initialize a ProcessBuilder to run a command using the system shell.booleansetExecute(java.io.File f, boolean canExecute)Set a file to be executable by the user.voidsetHidden(java.io.File path, boolean hidden)Set the hidden attribute for file whose name starts with a period.voidsetUmask(int umask)Set the umask, overriding any value observed from the shell.(package private) java.lang.StringshellQuote(java.lang.String cmd)Quote a string (such as a file system path obtained from a JavaFileorPathobject) such that it can be passed as first argument toFS.runInShell(String, String[]).booleansupportsAtomicCreateNewFile()Does this file system support atomic file creation via java.io.File#createNewFile()? In certain environments (e.g.booleansupportsExecute()Does this operating system and JRE support the execute flag on files?private static FS.LockTokentoken(boolean created, java.nio.file.Path p)private intumask()private static java.lang.StringuniqueLinkPath(java.io.File file)-
Methods inherited from class org.eclipse.jgit.util.FS
createSymLink, delete, detect, detect, discoverGitSystemConfig, execute, exists, fileAttributes, findHook, getFileStoreAttributes, getGitSystemConfig, internalRunHookIfPresent, isDirectory, isFile, isHidden, isSymLink, lastModified, lastModifiedInstant, lastModifiedInstant, length, list, readPipe, readPipe, readSymLink, relativize, resolve, resolveGrandparentFile, runHookIfPresent, runProcess, runProcess, searchPath, setAsyncFileStoreAttributes, setGitSystemConfig, setLastModified, setLastModified, setUserHome, supportsSymlinks, userHome, userHomeImpl
-
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
DEFAULT_GIT_LOCATION
private static final java.lang.String DEFAULT_GIT_LOCATION
- See Also:
- Constant Field Values
-
DEFAULT_UMASK
private static final int DEFAULT_UMASK
- See Also:
- Constant Field Values
-
umask
private volatile int umask
-
CAN_HARD_LINK
private static final java.util.Map<java.nio.file.FileStore,java.lang.Boolean> CAN_HARD_LINK
-
supportsAtomicFileCreation
private volatile FS_POSIX.AtomicFileCreation supportsAtomicFileCreation
-
-
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:
newInstancein classFS- 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
-
umask
private int umask()
-
readUmask
private static int readUmask()
- Returns:
- mask returned from running
umaskcommand in shell.
-
discoverGitExe
protected java.io.File discoverGitExe()
Discover the path to the Git executable.- Specified by:
discoverGitExein classFS- Returns:
- the path to the Git executable or
nullif it cannot be determined.
-
isCaseSensitive
public boolean isCaseSensitive()
Is this file system case sensitive- Specified by:
isCaseSensitivein classFS- 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:
supportsExecutein classFS- Returns:
- true if this implementation can provide reasonably accurate executable bit information; false otherwise.
-
canExecute
public boolean canExecute(java.io.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
fis a symbolic link this method returns false, rather than the state of the executable flags on the target file.- Specified by:
canExecutein classFS- Parameters:
f- abstract path to test.- Returns:
- true if the file is believed to be executable by the user.
-
setExecute
public boolean setExecute(java.io.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:
setExecutein classFS- 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.
-
apply
private static void apply(java.util.Set<java.nio.file.attribute.PosixFilePermission> set, int umask, java.nio.file.attribute.PosixFilePermission perm, int test)
-
runInShell
public java.lang.ProcessBuilder runInShell(java.lang.String cmd, java.lang.String[] args)Initialize a ProcessBuilder to run a command using the system shell.- Specified by:
runInShellin classFS- 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.
-
shellQuote
java.lang.String shellQuote(java.lang.String cmd)
Description copied from class:FSQuote a string (such as a file system path obtained from a JavaFileorPathobject) such that it can be passed as first argument toFS.runInShell(String, String[]).This default implementation returns the string unchanged.
- Overrides:
shellQuotein classFS- Parameters:
cmd- the String to quote- Returns:
- the quoted string
-
runHookIfPresent
public ProcessResult runHookIfPresent(Repository repository, java.lang.String hookName, java.lang.String[] args, java.io.OutputStream outRedirect, java.io.OutputStream errRedirect, java.lang.String stdinArgs) throws JGitInternalException
Checks whether the given hook is defined for the given repository, then runs it with the given arguments.- Overrides:
runHookIfPresentin classFS- 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 benull, but can be an empty array.outRedirect- A print stream on which to redirect the hook's stdout. Can benull, in which case the hook's standard output will be lost.errRedirect- A print stream on which to redirect the hook's stderr. Can benull, 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 benull.- 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:
retryFailedLockFileCommitin classFS- Returns:
- true if the caller should retry a failed rename of a lock file.
-
setHidden
public void setHidden(java.io.File path, boolean hidden) throws java.io.IOExceptionSet the hidden attribute for file whose name starts with a period.
-
getAttributes
public FS.Attributes getAttributes(java.io.File path)
Get the file attributes we care for.- Overrides:
getAttributesin classFS- Parameters:
path- aFileobject.- Returns:
- the file attributes we care for.
-
normalize
public java.io.File normalize(java.io.File file)
Normalize the unicode path to composed form.
-
normalize
public java.lang.String normalize(java.lang.String name)
Normalize the unicode path to composed form.
-
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:
supportsAtomicCreateNewFilein classFS- Returns:
- true if this implementation support atomic creation of new Files
by
File.createNewFile()
-
createNewFile
@Deprecated public boolean createNewFile(java.io.File lock) throws java.io.IOExceptionDeprecated.Description copied from class:FSCreate a new file. SeeFile.createNewFile(). Subclasses of this class may take care to provide a safe implementation for this even ifFS.supportsAtomicCreateNewFile()isfalse- Overrides:
createNewFilein classFS- Parameters:
lock- the file to be created- Returns:
trueif the file was created,falseif the file already existed- Throws:
java.io.IOException
-
createNewFileAtomic
public FS.LockToken createNewFileAtomic(java.io.File file) throws java.io.IOException
Create a new file. SeeFile.createNewFile(). Subclasses of this class may take care to provide a safe implementation for this even ifFS.supportsAtomicCreateNewFile()isfalseAn 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 ifcore.supportsAtomicCreateNewFile = falsethen 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:
createNewFileAtomicin classFS- 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:
java.io.IOException- Since:
- 5.0
- See Also:
- "https://www.time-travellers.org/shane/papers/NFS_considered_harmful.html"
-
token
private static FS.LockToken token(boolean created, @Nullable java.nio.file.Path p)
-
uniqueLinkPath
private static java.lang.String uniqueLinkPath(java.io.File file)
-
-