Top Description Inners Fields Constructors Methods
org.eclipse.jgit.util

public abstract Class FS

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.util.FS_POSIX, org.eclipse.jgit.util.FS_Win32
Static Imports
java.nio.charset.StandardCharsets.UTF_8, java.time.Instant.EPOCH

Abstraction to support various file system operations not in Java.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
FS.Attributes

File attributes we typically care for.

public static class
FS.ExecutionResult

Result of an executed process.

public static class
FS.FileStoreAttributes

Attributes of FileStores on this system

public static class
FS.FSFactory

This class creates FS instances.

private static class
private static class
public static class
FS.LockToken

A token representing a file created by createNewFileAtomic(File).

private static class
FS.StreamGobbler

This runnable will consume an input stream's content into an output stream as soon as it gets available.

Field Summary

Modifier and TypeField and Description
public static final FS
DETECTED

The auto-detected implementation selected for this operating system and JRE.

private static final Pattern
private static volatile FS.FSFactory
private volatile FS.Holder<File>
private static final Logger
protected static final WorkingTreeIterator.Entry[]
NO_ENTRIES

An empty array of entries, suitable as a return value for list(File, FileModeStrategy).

private volatile Boolean
private volatile FS.Holder<File>
private static final Pattern

Constructor Summary

AccessConstructor and Description
protected
FS()

Constructs a file system abstraction.

protected
FS(FS
the source FS to copy from.
src
)

Initialize this FS using another's current settings.

Method Summary

Modifier and TypeMethod and Description
public abstract boolean

Returns:

true if the file is believed to be executable by the user.
canExecute
(File
abstract path to test.
f
)

Determine if the file is executable (or not).

public FS.LockToken

Returns:

LockToken this token must be closed after the created file was deleted
createNewFileAtomic
(File
the file to be created
path
)

Create a new file.

private File
public void
delete(File
a java.io.File object.
f
)

Delete a file.

public static FS

Returns:

detected file system abstraction
detect
()

Auto-detect the appropriate file system abstraction.

public static FS

Returns:

detected file system abstraction
detect
(Boolean
  • Boolean.TRUE to assume that Cygwin is used in combination with jgit
  • Boolean.FALSE to assume that Cygwin is not used with jgit
  • null to auto-detect whether a Cygwin installation is present on the system and in this case assume that Cygwin is used
Note: this parameter is only relevant on Windows.
cygwinUsed
)

Auto-detect the appropriate file system abstraction, taking into account the presence of a Cygwin installation on the system.

private void
protected abstract File

Returns:

the path to the Git executable or null if it cannot be determined.
discoverGitExe
()

Discover the path to the Git executable.

protected File

Returns:

the path to the system-wide Git configuration file or null if it cannot be determined.
discoverGitSystemConfig
()

Discover the path to the system-wide Git configuration file

public FS.ExecutionResult

Returns:

The result of the executed command
execute
(ProcessBuilder
The command to be executed
pb
,
InputStream
The standard input stream passed to the process
in
)

Execute a command defined by a java.lang.ProcessBuilder.

public boolean

Returns:

true if path exists
exists
(File
a java.io.File object.
path
)

Tests if the path exists, in case of a symbolic link, true even if the target does not exist

public BasicFileAttributes

Returns:

BasicFileAttributes of the file
fileAttributes
(File
the file
file
)

Return all the attributes of a file, without following symbolic links.

public File

Returns:

The java.io.File containing this particular hook if it exists in the given repository, null otherwise.
findHook
(Repository
The repository within which to find a hook.
repository
,
String
The name of the hook we're trying to find.
hookName
)

Tries to find a hook matching the given one in the given repository.

public FS.Attributes

Returns:

the file attributes we care for.
getAttributes
(File
a java.io.File object.
path
)

Get the file attributes we care for.

public File

Returns:

common dir path
getCommonDir
(File
the .git folder
dir
)

Get common dir path.

public static FS.FileStoreAttributes

Returns:

measured filesystem timestamp resolution
getFileStoreAttributes
(Path
the directory under which the probe file will be created to measure the timer resolution.
dir
)

Get cached FileStore attributes, if not yet available measure them using a probe file under the given directory.

public File

Returns:

the currently used path to the system-wide Git configuration file or null if none has been set.
getGitSystemConfig
()

Get the currently used path to the system-wide Git configuration file.

private File
private File
getRunDirectory(Repository repository, String hookName)

protected ProcessResult

Returns:

The ProcessResult describing this hook's execution.
internalRunHookIfPresent
(Repository
The repository for which a hook should be run.
repository
,
String
The name of the hook to be executed.
hookName
,
String[]
Arguments to pass to this hook. Cannot be null, but can be an empty array.
args
,
OutputStream
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.
outRedirect
,
OutputStream
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.
errRedirect
,
String
A string to pass on to the standard input of the hook. May be null.
stdinArgs
)

See runHookIfPresent(Repository, String, String[], OutputStream, OutputStream, String) .

public abstract boolean

Returns:

true if this implementation is case sensitive
isCaseSensitive
()

Is this file system case sensitive

public boolean

Returns:

true if file is a directory,
isDirectory
(File
a java.io.File object.
path
)

Check if path is a directory.

public boolean

Returns:

true if path represents a regular file
isFile
(File
a java.io.File object.
path
)

Examine if path represents a regular file.

public boolean

Returns:

true if path is hidden, either starts with . on unix or has the hidden attribute in windows
isHidden
(File
a java.io.File object.
path
)

Whether path is hidden, either starts with .

public Instant

Returns:

last modified time of p
lastModifiedInstant
(Path
a Path object.
p
)

Get the last modified time of a file system object.

public Instant

Returns:

last modified time of p
lastModifiedInstant
(File
a File object.
f
)

Get the last modified time of a file system object.

public long

Returns:

length of a file
length
(File
a java.io.File object.
path
)

Get the length of a file or link, If the OS/JRE supports symbolic links it's the length of the link, else the length of the target.

public WorkingTreeIterator.Entry[]

Returns:

an array of entries for the children
list
(File
to get the children of
directory
,
FileTreeIterator.FileModeStrategy
to use to calculate the git mode of a child
fileModeStrategy
)

Enumerates children of a directory.

private long
makeVersion(int major, int minor, int patch)

public abstract FS

Returns:

a new instance of the same type of FS.
newInstance
()

Create a new instance of the same type of FS.

public File

Returns:

NFC-format File
normalize
(File
a java.io.File object.
file
)

Normalize the unicode path to composed form.

public String

Returns:

NFC-format string
normalize
(String
path name
name
)

Normalize the unicode path to composed form.

private long
protected static String

Returns:

the one-line output of the command or null if there is none
readPipe
(File
Working directory for the command
dir
,
String[]
as component array
command
,
String
to be used to parse the command's output
encoding
)

Execute a command and return a single line of output as a String

protected static String

Returns:

the one-line output of the command or null if there is none
readPipe
(File
Working directory for the command
dir
,
String[]
as component array
command
,
String
to be used to parse the command's output
encoding
,
Map<String, String>
Map of environment variables to be merged with those of the current process
env
)

Execute a command and return a single line of output as a String

public String

Returns:

A relative path that, when resolved against base, will yield the original other.
relativize
(String
The path against which other should be relativized.
base
,
String
The path that will be made relative to base.
other
)

See org.eclipse.jgit.util.FileUtils#relativizePath(String, String, String, boolean).

public File

Returns:

the translated path. new File(dir,name) if this platform does not require path name translation.
resolve
(File
directory relative to which the path name is.
dir
,
String
path name to translate.
name
)

Resolve this file to its actual path name that the JRE can use.

protected static File

Returns:

the parent directory of this file's parent directory or null in case there's no grandparent directory
resolveGrandparentFile
(File
a java.io.File object.
grandchild
)

Get the parent directory of this file's parent directory

public abstract boolean

Returns:

true if the caller should retry a failed rename of a lock file.
retryFailedLockFileCommit
()

Does this file system have problems with atomic renames?

public ProcessResult

Returns:

The ProcessResult describing this hook's execution.
runHookIfPresent
(Repository
The repository for which a hook should be run.
repository
,
String
The name of the hook to be executed.
hookName
,
String[]
Arguments to pass to this hook. Cannot be null, but can be an empty array.
args
)

Checks whether the given hook is defined for the given repository, then runs it with the given arguments.

public ProcessResult

Returns:

The ProcessResult describing this hook's execution.
runHookIfPresent
(Repository
The repository for which a hook should be run.
repository
,
String
The name of the hook to be executed.
hookName
,
String[]
Arguments to pass to this hook. Cannot be null, but can be an empty array.
args
,
OutputStream
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.
outRedirect
,
OutputStream
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.
errRedirect
,
String
A string to pass on to the standard input of the hook. May be null.
stdinArgs
)

Checks whether the given hook is defined for the given repository, then runs it with the given arguments.

public abstract ProcessBuilder

Returns:

a partially completed process builder. Caller should finish populating directory, environment, and then start the process.
runInShell
(String
command to execute. This string should originate from the end-user, and thus is platform specific.
cmd
,
String[]
arguments to pass to command. These should be protected from shell evaluation.
args
)

Initialize a ProcessBuilder to run a command using the system shell.

public int

Returns:

the exit value of this process.
runProcess
(ProcessBuilder
The process builder configured for this process.
processBuilder
,
OutputStream
A OutputStream on which to redirect the processes stdout. Can be null, in which case the processes standard output will be lost.
outRedirect
,
OutputStream
A OutputStream on which to redirect the processes stderr. Can be null, in which case the processes standard error will be lost.
errRedirect
,
String
A string to pass on to the standard input of the hook. Can be null.
stdinArgs
)

Runs the given process until termination, clearing its stdout and stderr streams on-the-fly.

public int

Returns:

the return code of this process.
runProcess
(ProcessBuilder
The process builder configured for this process.
processBuilder
,
OutputStream
An OutputStream on which to redirect the processes stdout. Can be null, in which case the processes standard output will be lost.
outRedirect
,
OutputStream
An OutputStream on which to redirect the processes stderr. Can be null, in which case the processes standard error will be lost.
errRedirect
,
InputStream
An InputStream from which to redirect the processes stdin. Can be null, in which case the process doesn't get any data over stdin. It is assumed that the whole InputStream will be consumed by the process. The method will close the inputstream after all bytes are read.
inRedirect
)

Runs the given process until termination, clearing its stdout and stderr streams on-the-fly.

private File
protected static File

Returns:

the first match found, or null
searchPath
(String
List of paths to search separated by File.pathSeparator
path
,
String...
Files to search for in the given path
lookFor
)

Searches the given path to see if it contains one of the given files.

public abstract boolean

Returns:

true if the change succeeded; false otherwise.
setExecute
(File
path to modify the executable status of.
f
,
boolean
true to enable execution; false to disable it.
canExec
)

Set a file to be executable by the user.

public FS

Returns:

this
setGitSystemConfig
(File
the path to the config file.
configFile
)

Set the path to the system-wide Git configuration file to use.

public void
setHidden(File
a java.io.File object.
path
,
boolean
whether to set the file hidden
hidden
)

Set the hidden attribute for file whose name starts with a period.

public void
setLastModified(Path
a Path object.
p
,
Instant
last modified time
time
)

Set the last modified time of a file system object.

public FS

Returns:

this.
setUserHome
(File
the location of the user's preferences; null if there is no home directory for the current user.
path
)

Set the user's home directory location.

pack-priv String

Returns:

the quoted string
shellQuote
(String
the String to quote
cmd
)

Quote a string (such as a file system path obtained from a Java File or Path object) such that it can be passed as first argument to runInShell(String, String[]).

private static boolean

Returns:

true if the pool has been properly shutdown, false otherwise.
shutdownAndAwaitTermination
(ExecutorService
the pool to shutdown
pool
)

Shuts down an ExecutorService in two phases, first by calling shutdown to reject incoming tasks, and then calling shutdownNow, if necessary, to cancel any lingering tasks.

public boolean

Returns:

true if this implementation support atomic creation of new Files by java.io.File#createNewFile()
supportsAtomicCreateNewFile
()

Does this file system support atomic file creation via java.io.File#createNewFile()?

public abstract boolean

Returns:

true if this implementation can provide reasonably accurate executable bit information; false otherwise.
supportsExecute
()

Does this operating system and JRE support the execute flag on files?

public File

Returns:

the user's home directory; null if the user does not have one.
userHome
()

Determine the user's home directory (location where preferences are).

protected File

Returns:

the user's home directory; null if the user does not have one.
userHomeImpl
()

Determine the user's home directory (location where preferences are).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait