Modifier and Type | Class and Description |
---|---|
static class |
FS.Attributes
File attributes we typically care for.
|
static class |
FS.ExecutionResult
Result of an executed process.
|
static class |
FS.FSFactory
This class creates FS instances.
|
Modifier and Type | Field and Description |
---|---|
static FS |
DETECTED
The auto-detected implementation selected for this operating system and JRE.
|
protected static WorkingTreeIterator.Entry[] |
NO_ENTRIES
An empty array of entries, suitable as a return value for
#list(File, FileModeStrategy) . |
Modifier | Constructor and Description |
---|---|
protected |
FS()
Constructs a file system abstraction.
|
protected |
FS(FS src)
Initialize this FS using another's current settings.
|
Modifier and Type | Method and Description |
---|---|
abstract boolean |
canExecute(File f)
Determine if the file is executable (or not).
|
boolean |
createNewFile(File path)
Create a new file.
|
void |
createSymLink(File path,
String target)
Create a symbolic link
|
void |
delete(File f)
Delete a file.
|
static FS |
detect()
Auto-detect the appropriate file system abstraction.
|
static FS |
detect(Boolean cygwinUsed)
Auto-detect the appropriate file system abstraction, taking into account
the presence of a Cygwin installation on the system.
|
protected abstract File |
discoverGitExe()
Discover the path to the Git executable.
|
protected File |
discoverGitSystemConfig()
Discover the path to the system-wide Git configuration file
|
FS.ExecutionResult |
execute(ProcessBuilder pb,
InputStream in)
Execute a command defined by a
ProcessBuilder . |
boolean |
exists(File path)
Tests if the path exists, in case of a symbolic link, true even if the
target does not exist
|
File |
findHook(Repository repository,
String hookName)
Tries to find a hook matching the given one in the given repository.
|
FS.Attributes |
getAttributes(File path)
Get the file attributes we care for.
|
File |
getGitSystemConfig()
Get the currently used path to the system-wide Git configuration file.
|
protected ProcessResult |
internalRunHookIfPresent(Repository repository,
String hookName,
String[] args,
PrintStream outRedirect,
PrintStream errRedirect,
String stdinArgs)
|
abstract boolean |
isCaseSensitive()
Is this file system case sensitive
|
boolean |
isDirectory(File path)
Check if path is a directory.
|
boolean |
isFile(File path)
Examine if path represents a regular file.
|
boolean |
isHidden(File path)
Whether path is hidden, either starts with .
|
boolean |
isSymLink(File path)
Whether the path is a symbolic link (and we support these).
|
long |
lastModified(File f)
Get the last modified time of a file system object.
|
long |
length(File 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.
|
WorkingTreeIterator.Entry[] |
list(File directory,
FileTreeIterator.FileModeStrategy fileModeStrategy)
Enumerates children of a directory.
|
abstract FS |
newInstance()
Create a new instance of the same type of FS.
|
File |
normalize(File file)
Normalize the unicode path to composed form.
|
String |
normalize(String name)
Normalize the unicode path to composed form.
|
protected static String |
readPipe(File dir,
String[] command,
String encoding)
Execute a command and return a single line of output as a String
|
protected static String |
readPipe(File dir,
String[] command,
String encoding,
Map<String,String> env)
Execute a command and return a single line of output as a String
|
String |
readSymLink(File path)
Check if a file is a symbolic link and read it
|
String |
relativize(String base,
String other)
|
File |
resolve(File dir,
String name)
Resolve this file to its actual path name that the JRE can use.
|
protected static File |
resolveGrandparentFile(File grandchild)
Get the parent directory of this file's parent directory
|
abstract boolean |
retryFailedLockFileCommit()
Does this file system have problems with atomic renames?
|
ProcessResult |
runHookIfPresent(Repository repository,
String hookName,
String[] args)
Checks whether the given hook is defined for the given repository, then
runs it with the given arguments.
|
ProcessResult |
runHookIfPresent(Repository repository,
String hookName,
String[] args,
PrintStream outRedirect,
PrintStream errRedirect,
String stdinArgs)
Checks whether the given hook is defined for the given repository, then
runs it with the given arguments.
|
abstract ProcessBuilder |
runInShell(String cmd,
String[] args)
Initialize a ProcessBuilder to run a command using the system shell.
|
int |
runProcess(ProcessBuilder processBuilder,
OutputStream outRedirect,
OutputStream errRedirect,
InputStream inRedirect)
Runs the given process until termination, clearing its stdout and stderr
streams on-the-fly.
|
int |
runProcess(ProcessBuilder processBuilder,
OutputStream outRedirect,
OutputStream errRedirect,
String stdinArgs)
Runs the given process until termination, clearing its stdout and stderr
streams on-the-fly.
|
protected static File |
searchPath(String path,
String... lookFor)
Searches the given path to see if it contains one of the given files.
|
abstract boolean |
setExecute(File f,
boolean canExec)
Set a file to be executable by the user.
|
FS |
setGitSystemConfig(File configFile)
Set the path to the system-wide Git configuration file to use.
|
void |
setHidden(File path,
boolean hidden)
Set the hidden attribute for file whose name starts with a period.
|
void |
setLastModified(File f,
long time)
Set the last modified time of a file system object.
|
FS |
setUserHome(File path)
Set the user's home directory location.
|
boolean |
supportsAtomicCreateNewFile()
Does this file system support atomic file creation via
java.io.File#createNewFile()? In certain environments (e.g.
|
abstract boolean |
supportsExecute()
Does this operating system and JRE support the execute flag on files?
|
boolean |
supportsSymlinks()
Does this operating system and JRE supports symbolic links.
|
File |
userHome()
Determine the user's home directory (location where preferences are).
|
protected File |
userHomeImpl()
Determine the user's home directory (location where preferences are).
|
protected static final WorkingTreeIterator.Entry[] NO_ENTRIES
#list(File, FileModeStrategy)
.public static final FS DETECTED
protected FS()
protected FS(FS src)
src
- the source FS to copy from.public static FS detect()
public static FS detect(Boolean cygwinUsed)
cygwinUsed
- Boolean.TRUE
to assume that Cygwin is used in
combination with jgitBoolean.FALSE
to assume that Cygwin is
not used with jgitnull
to auto-detect whether a Cygwin
installation is present on the system and in this case assume
that Cygwin is usedpublic abstract FS newInstance()
public abstract boolean supportsExecute()
public boolean supportsAtomicCreateNewFile()
File.createNewFile()
public boolean supportsSymlinks()
public abstract boolean isCaseSensitive()
public abstract boolean canExecute(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.
f
- abstract path to test.public abstract boolean setExecute(File f, boolean canExec)
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.
f
- path to modify the executable status of.canExec
- true to enable execution; false to disable it.public long lastModified(File f) throws IOException
f
- a File
object.IOException
public void setLastModified(File f, long time) throws IOException
f
- a File
object.time
- last modified timeIOException
public long length(File path) throws IOException
path
- a File
object.IOException
public void delete(File f) throws IOException
f
- a File
object.IOException
- this may be a Java7 subclass with detailed informationpublic File resolve(File dir, String name)
This method can be relatively expensive. Computing a translation may require forking an external process per path name translated. Callers should try to minimize the number of translations necessary by caching the results.
Not all platforms and JREs require path name translation. Currently only Cygwin on Win32 require translation for Cygwin based paths.
dir
- directory relative to which the path name is.name
- path name to translate.new File(dir,name)
if this
platform does not require path name translation.public File userHome()
This method can be expensive on the first invocation if path name translation is required. Subsequent invocations return a cached result.
Not all platforms and JREs require path name translation. Currently only Cygwin on Win32 requires translation of the Cygwin HOME directory.
public FS setUserHome(File path)
path
- the location of the user's preferences; null if there is no
home directory for the current user.this
.public abstract boolean retryFailedLockFileCommit()
protected File userHomeImpl()
protected static File searchPath(String path, String... lookFor)
path
- List of paths to search separated by File.pathSeparatorlookFor
- Files to search for in the given path@Nullable protected static String readPipe(File dir, String[] command, String encoding) throws CommandFailedException
dir
- Working directory for the commandcommand
- as component arrayencoding
- to be used to parse the command's outputnull
if there is
noneCommandFailedException
- thrown when the command failed (return code was non-zero)@Nullable protected static String readPipe(File dir, String[] command, String encoding, Map<String,String> env) throws CommandFailedException
dir
- Working directory for the commandcommand
- as component arrayencoding
- to be used to parse the command's outputenv
- Map of environment variables to be merged with those of the
current processnull
if there is
noneCommandFailedException
- thrown when the command failed (return code was non-zero)protected abstract File discoverGitExe()
null
if it cannot be
determined.protected File discoverGitSystemConfig()
null
if it cannot be determined.public File getGitSystemConfig()
null
if none has been set.public FS setGitSystemConfig(File configFile)
configFile
- the path to the config file.this
protected static File resolveGrandparentFile(File grandchild)
grandchild
- a File
object.null
in case there's no grandparent directorypublic String readSymLink(File path) throws IOException
path
- a File
object.IOException
public boolean isSymLink(File path) throws IOException
path
- a File
object.IOException
public boolean exists(File path)
path
- a File
object.public boolean isDirectory(File path)
path
- a File
object.public boolean isFile(File path)
path
- a File
object.public boolean isHidden(File path) throws IOException
path
- a File
object.IOException
public void setHidden(File path, boolean hidden) throws IOException
path
- a File
object.hidden
- whether to set the file hiddenIOException
public void createSymLink(File path, String target) throws IOException
path
- a File
object.target
- target path of the symlinkIOException
public boolean createNewFile(File path) throws IOException
File.createNewFile()
. Subclasses
of this class may take care to provide a safe implementation for this
even if supportsAtomicCreateNewFile()
is false
path
- the file to be createdtrue
if the file was created, false
if
the file already existedIOException
public String relativize(String base, String other)
base
- The path against which other
should be
relativized.other
- The path that will be made relative to base
.base
,
will yield the original other
.FileUtils.relativizePath(String, String, String, boolean)
public WorkingTreeIterator.Entry[] list(File directory, FileTreeIterator.FileModeStrategy fileModeStrategy)
directory
- to get the children offileModeStrategy
- to use to calculate the git mode of a childpublic ProcessResult runHookIfPresent(Repository repository, String hookName, String[] args) throws JGitInternalException
The hook's standard output and error streams will be redirected to
System.out
and System.err
respectively. The
hook will have no stdin.
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.JGitInternalException
- if we fail to run the hook somehow. Causes may include an
interrupted process or I/O errors.public ProcessResult runHookIfPresent(Repository repository, String hookName, String[] args, PrintStream outRedirect, PrintStream errRedirect, String stdinArgs) throws JGitInternalException
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.protected ProcessResult internalRunHookIfPresent(Repository repository, String hookName, String[] args, PrintStream outRedirect, PrintStream errRedirect, String stdinArgs) throws JGitInternalException
runHookIfPresent(Repository, String, String[], PrintStream, PrintStream, String)
. Should only be called by FS supporting shell scripts execution.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 File findHook(Repository repository, String hookName)
repository
- The repository within which to find a hook.hookName
- The name of the hook we're trying to find.File
containing this particular hook if it
exists in the given repository, null
otherwise.public int runProcess(ProcessBuilder processBuilder, OutputStream outRedirect, OutputStream errRedirect, String stdinArgs) throws IOException, InterruptedException
processBuilder
- The process builder configured for this process.outRedirect
- A OutputStream on which to redirect the processes stdout. Can
be null
, in which case the processes standard
output will be lost.errRedirect
- A OutputStream on which to redirect the processes stderr. Can
be null
, in which case the processes standard
error will be lost.stdinArgs
- A string to pass on to the standard input of the hook. Can be
null
.IOException
- if an I/O error occurs while executing this process.InterruptedException
- if the current thread is interrupted while waiting for the
process to end.public int runProcess(ProcessBuilder processBuilder, OutputStream outRedirect, OutputStream errRedirect, InputStream inRedirect) throws IOException, InterruptedException
processBuilder
- The process builder configured for this process.outRedirect
- An OutputStream on which to redirect the processes stdout. Can
be null
, in which case the processes standard
output will be lost.errRedirect
- An OutputStream on which to redirect the processes stderr. Can
be null
, in which case the processes standard
error will be lost.inRedirect
- 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.IOException
- if an I/O error occurs while executing this process.InterruptedException
- if the current thread is interrupted while waiting for the
process to end.public abstract ProcessBuilder runInShell(String cmd, String[] args)
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 FS.ExecutionResult execute(ProcessBuilder pb, InputStream in) throws IOException, InterruptedException
ProcessBuilder
.pb
- The command to be executedin
- The standard input stream passed to the processInterruptedException
IOException
public FS.Attributes getAttributes(File path)
path
- a File
object.public File normalize(File file)
file
- a File
object.Copyright © 2018 Eclipse JGit Project. All rights reserved.