public class FS_POSIX extends FS
Modifier and Type | Class and Description |
---|---|
private static class |
FS_POSIX.AtomicFileCreation |
FS.Attributes, FS.ExecutionResult, FS.FileStoreAttributes, FS.FSFactory, FS.LockToken
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.nio.file.FileStore,java.lang.Boolean> |
CAN_HARD_LINK |
private static int |
DEFAULT_UMASK |
private static org.slf4j.Logger |
LOG |
private FS_POSIX.AtomicFileCreation |
supportsAtomicFileCreation |
private int |
umask |
DETECTED, NO_ENTRIES
Modifier | Constructor and Description |
---|---|
protected |
FS_POSIX()
Default constructor.
|
protected |
FS_POSIX(FS src)
Constructor
|
Modifier and Type | Method and Description |
---|---|
private static void |
apply(java.util.Set<java.nio.file.attribute.PosixFilePermission> set,
int umask,
java.nio.file.attribute.PosixFilePermission perm,
int test) |
boolean |
canExecute(java.io.File f)
Determine if the file is executable (or not).
|
boolean |
createNewFile(java.io.File lock)
Deprecated.
|
FS.LockToken |
createNewFileAtomic(java.io.File file)
Create a new file.
|
protected java.io.File |
discoverGitExe()
Discover the path to the Git executable.
|
FS.Attributes |
getAttributes(java.io.File path)
Get the file attributes we care for.
|
boolean |
isCaseSensitive()
Is this file system case sensitive
|
FS |
newInstance()
Create a new instance of the same type of FS.
|
java.io.File |
normalize(java.io.File file)
Normalize the unicode path to composed form.
|
java.lang.String |
normalize(java.lang.String name)
Normalize the unicode path to composed form.
|
private static int |
readUmask() |
boolean |
retryFailedLockFileCommit()
Does this file system have problems with atomic renames?
|
ProcessResult |
runHookIfPresent(Repository repository,
java.lang.String hookName,
java.lang.String[] args,
java.io.PrintStream outRedirect,
java.io.PrintStream 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.ProcessBuilder |
runInShell(java.lang.String cmd,
java.lang.String[] args)
Initialize a ProcessBuilder to run a command using the system shell.
|
boolean |
setExecute(java.io.File f,
boolean canExecute)
Set a file to be executable by the user.
|
void |
setHidden(java.io.File path,
boolean hidden)
Set the hidden attribute for file whose name starts with a period.
|
void |
setUmask(int umask)
Set the umask, overriding any value observed from the shell.
|
boolean |
supportsAtomicCreateNewFile()
Does this file system support atomic file creation via
java.io.File#createNewFile()? In certain environments (e.g.
|
boolean |
supportsExecute()
Does this operating system and JRE support the execute flag on files?
|
private static FS.LockToken |
token(boolean created,
java.nio.file.Path p) |
private int |
umask() |
private static java.lang.String |
uniqueLinkPath(java.io.File file) |
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
private static final org.slf4j.Logger LOG
private static final int DEFAULT_UMASK
private volatile int umask
private static final java.util.Map<java.nio.file.FileStore,java.lang.Boolean> CAN_HARD_LINK
private volatile FS_POSIX.AtomicFileCreation supportsAtomicFileCreation
protected FS_POSIX()
protected FS_POSIX(FS src)
src
- FS to copy some settings frompublic FS newInstance()
newInstance
in class FS
public void setUmask(int umask)
umask
- mask to apply when creating files.private int umask()
private static int readUmask()
umask
command in shell.protected java.io.File discoverGitExe()
discoverGitExe
in class FS
null
if it cannot be
determined.public boolean isCaseSensitive()
isCaseSensitive
in class FS
public boolean supportsExecute()
supportsExecute
in class FS
public boolean canExecute(java.io.File f)
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.
canExecute
in class FS
f
- abstract path to test.public boolean setExecute(java.io.File f, boolean canExecute)
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.
setExecute
in class FS
f
- path to modify the executable status of.canExecute
- true to enable execution; false to disable it.private static void apply(java.util.Set<java.nio.file.attribute.PosixFilePermission> set, int umask, java.nio.file.attribute.PosixFilePermission perm, int test)
public java.lang.ProcessBuilder runInShell(java.lang.String cmd, java.lang.String[] args)
runInShell
in class FS
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.public ProcessResult runHookIfPresent(Repository repository, java.lang.String hookName, java.lang.String[] args, java.io.PrintStream outRedirect, java.io.PrintStream errRedirect, java.lang.String stdinArgs) throws JGitInternalException
runHookIfPresent
in class FS
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
.JGitInternalException
- if we fail to run the hook somehow. Causes may include an
interrupted process or I/O errors.public boolean retryFailedLockFileCommit()
retryFailedLockFileCommit
in class FS
public void setHidden(java.io.File path, boolean hidden) throws java.io.IOException
public FS.Attributes getAttributes(java.io.File path)
getAttributes
in class FS
path
- a File
object.public java.io.File normalize(java.io.File file)
public java.lang.String normalize(java.lang.String name)
public boolean supportsAtomicCreateNewFile()
supportsAtomicCreateNewFile
in class FS
File.createNewFile()
@Deprecated public boolean createNewFile(java.io.File lock) throws java.io.IOException
FS
File.createNewFile()
. Subclasses
of this class may take care to provide a safe implementation for this
even if FS.supportsAtomicCreateNewFile()
is false
createNewFile
in class FS
lock
- the file to be createdtrue
if the file was created, false
if
the file already existedjava.io.IOException
public FS.LockToken createNewFileAtomic(java.io.File file) throws java.io.IOException
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.
createNewFileAtomic
in class FS
file
- the unique file to be created atomicallyjava.io.IOException
private static FS.LockToken token(boolean created, @Nullable java.nio.file.Path p)
private static java.lang.String uniqueLinkPath(java.io.File file)