Modifier and Type | Class and Description |
---|---|
static class |
FS.Attributes
File attributes we typically care for.
|
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.
|
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).
|
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 |
discoverGitPrefix() |
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,
Hook hook)
Tries to find a hook matching the given one in the given repository.
|
FS.Attributes |
getAttributes(File path) |
File |
gitPrefix() |
protected ProcessResult |
internalRunIfPresent(Repository repository,
Hook hook,
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) |
boolean |
isSymLink(File path) |
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.
|
abstract FS |
newInstance() |
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
|
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.
|
abstract boolean |
retryFailedLockFileCommit()
Does this file system have problems with atomic renames?
|
ProcessResult |
runIfPresent(Repository repository,
Hook hook,
String[] args)
Checks whether the given hook is defined for the given repository, then
runs it with the given arguments.
|
ProcessResult |
runIfPresent(Repository repository,
Hook hook,
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 ProcesssBuilder to run a command using the system shell.
|
protected int |
runProcess(ProcessBuilder hookProcessBuilder,
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 |
setGitPrefix(File path)
Set the $prefix directory C Git uses.
|
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.
|
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).
|
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 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
- IOException
public void setLastModified(File f, long time) throws IOException
f
- time
- IOException
public long length(File path) throws IOException
path
- IOException
public void delete(File f) throws IOException
f
- 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 pathprotected static String readPipe(File dir, String[] command, String encoding)
dir
- Working directory for the commandcommand
- as component arrayencoding
- public File gitPrefix()
protected abstract File discoverGitPrefix()
public FS setGitPrefix(File path)
path
- the directory. Null if C Git is not installed.this
public String readSymLink(File path) throws IOException
path
- IOException
public boolean isSymLink(File path) throws IOException
path
- IOException
public boolean exists(File path)
path
- public boolean isDirectory(File path)
path
- public boolean isFile(File path)
path
- public boolean isHidden(File path) throws IOException
path
- IOException
public void setHidden(File path, boolean hidden) throws IOException
path
- hidden
- IOException
public void createSymLink(File path, String target) throws IOException
path
- target
- IOException
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.relativize(String, String)
public ProcessResult runIfPresent(Repository repository, Hook hook, 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.hook
- 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 runIfPresent(Repository repository, Hook hook, String[] args, PrintStream outRedirect, PrintStream errRedirect, String stdinArgs) throws JGitInternalException
repository
- The repository for which a hook should be run.hook
- 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 internalRunIfPresent(Repository repository, Hook hook, String[] args, PrintStream outRedirect, PrintStream errRedirect, String stdinArgs) throws JGitInternalException
runIfPresent(Repository, Hook, String[], PrintStream, PrintStream, String)
. Should only be called by FS supporting shell scripts execution.repository
- The repository for which a hook should be run.hook
- 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, Hook hook)
repository
- The repository within which to find a hook.hook
- The hook we're trying to find.File
containing this particular hook if it exists in
the given repository, null
otherwise.protected int runProcess(ProcessBuilder hookProcessBuilder, OutputStream outRedirect, OutputStream errRedirect, String stdinArgs) throws IOException, InterruptedException
hookProcessBuilder
- The process builder configured for this hook.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. Can be
null
.IOException
- if an I/O error occurs while executing this hook.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.Attributes getAttributes(File path)
path
- public File normalize(File file)
file
- Copyright © 2015. All rights reserved.