class TransportSftp.SftpObjectDB extends WalkRemoteObjectDatabase
WalkRemoteObjectDatabase.FileStream
Modifier and Type | Field and Description |
---|---|
private FtpChannel |
ftp |
private java.lang.String |
objectsPath |
INFO_PACKS, INFO_REFS, ROOT_DIR
Constructor and Description |
---|
SftpObjectDB(java.lang.String path) |
SftpObjectDB(TransportSftp.SftpObjectDB parent,
java.lang.String p) |
Modifier and Type | Method and Description |
---|---|
(package private) void |
close()
Close any resources used by this connection.
|
(package private) void |
deleteFile(java.lang.String path)
Delete a file from the object database.
|
(package private) java.util.Collection<WalkRemoteObjectDatabase> |
getAlternates()
Obtain alternate connections to alternate object databases (if any).
|
(package private) java.util.Collection<java.lang.String> |
getPackNames()
Obtain the list of available packs (if any).
|
(package private) URIish |
getURI() |
private Ref.Storage |
loose(Ref r) |
private void |
mkdir_p(java.lang.String path) |
(package private) WalkRemoteObjectDatabase.FileStream |
open(java.lang.String path)
Open a single file for reading.
|
(package private) WalkRemoteObjectDatabase |
openAlternate(java.lang.String location)
Create a new connection for a discovered alternate object database
|
(package private) java.util.Map<java.lang.String,Ref> |
readAdvertisedRefs() |
private void |
readLooseRefs(java.util.TreeMap<java.lang.String,Ref> avail,
java.lang.String dir,
java.lang.String prefix) |
private Ref |
readRef(java.util.TreeMap<java.lang.String,Ref> avail,
java.lang.String path,
java.lang.String name) |
(package private) void |
writeFile(java.lang.String path,
byte[] data)
Atomically write a remote file.
|
(package private) java.io.OutputStream |
writeFile(java.lang.String path,
ProgressMonitor monitor,
java.lang.String monitorTask)
Open a remote file for writing.
|
deleteRef, deleteRefLog, openReader, readAlternates, readPackedRefs, writeInfoPacks, writeRef
private final java.lang.String objectsPath
private FtpChannel ftp
SftpObjectDB(java.lang.String path) throws TransportException
TransportException
SftpObjectDB(TransportSftp.SftpObjectDB parent, java.lang.String p) throws TransportException
TransportException
URIish getURI()
getURI
in class WalkRemoteObjectDatabase
java.util.Collection<WalkRemoteObjectDatabase> getAlternates() throws java.io.IOException
WalkRemoteObjectDatabase
Alternates are typically read from the file
Constants.INFO_ALTERNATES
or
Constants.INFO_HTTP_ALTERNATES
.
The content of each line must be resolved
by the implementation and a new database reference should be returned to
represent the additional location.
Alternates may reuse the same network connection handle, however the
fetch connection will WalkRemoteObjectDatabase.close()
each created alternate.
getAlternates
in class WalkRemoteObjectDatabase
java.io.IOException
- The connection is unable to read the remote repository's list
of configured alternates.WalkRemoteObjectDatabase openAlternate(java.lang.String location) throws java.io.IOException
WalkRemoteObjectDatabase
This method is typically called by WalkRemoteObjectDatabase.readAlternates(String)
when
subclasses us the generic alternate parsing logic for their
implementation of WalkRemoteObjectDatabase.getAlternates()
.
openAlternate
in class WalkRemoteObjectDatabase
location
- the location of the new alternate, relative to the current
object database.java.io.IOException
- The database connection cannot be established with the
alternate, such as if the alternate location does not
actually exist and the connection's constructor attempts to
verify that.java.util.Collection<java.lang.String> getPackNames() throws java.io.IOException
WalkRemoteObjectDatabase
Pack names should be the file name in the packs directory, that is
pack-035760ab452d6eebd123add421f253ce7682355a.pack
. Index
names should not be included in the returned collection.
getPackNames
in class WalkRemoteObjectDatabase
java.io.IOException
- The connection is unable to read the remote repository's list
of available pack files.WalkRemoteObjectDatabase.FileStream open(java.lang.String path) throws java.io.IOException
WalkRemoteObjectDatabase
Implementors should make every attempt possible to ensure
FileNotFoundException
is used when the remote object does not
exist. However when fetching over HTTP some misconfigured servers may
generate a 200 OK status message (rather than a 404 Not Found) with an
HTML formatted message explaining the requested resource does not exist.
Callers such as WalkFetchConnection
are prepared to handle this
by validating the content received, and assuming content that fails to
match its hash is an incorrectly phrased FileNotFoundException.
This method is recommended for already compressed files like loose objects
and pack files. For text files, see WalkRemoteObjectDatabase.openReader(String)
.
open
in class WalkRemoteObjectDatabase
path
- location of the file to read, relative to this objects
directory (e.g.
cb/95df6ab7ae9e57571511ef451cf33767c26dd2
or
pack/pack-035760ab452d6eebd123add421f253ce7682355a.pack
).java.io.FileNotFoundException
- the requested file does not exist at the given location.java.io.IOException
- The connection is unable to read the remote's file, and the
failure occurred prior to being able to determine if the file
exists, or after it was determined to exist but before the
stream could be created.void deleteFile(java.lang.String path) throws java.io.IOException
WalkRemoteObjectDatabase
Path may start with ../
to request deletion of a file that
resides in the repository itself.
When possible empty directories must be removed, up to but not including the current object database directory itself.
This method does not support deletion of directories.
deleteFile
in class WalkRemoteObjectDatabase
path
- name of the item to be removed, relative to the current object
database.java.io.IOException
- deletion is not supported, or deletion failed.java.io.OutputStream writeFile(java.lang.String path, ProgressMonitor monitor, java.lang.String monitorTask) throws java.io.IOException
WalkRemoteObjectDatabase
Path may start with ../
to request writing of a file that
resides in the repository itself.
The requested path may or may not exist. If the path already exists as a file the file should be truncated and completely replaced.
This method creates any missing parent directories, if necessary.
writeFile
in class WalkRemoteObjectDatabase
path
- name of the file to write, relative to the current object
database.monitor
- (optional) progress monitor to post write completion to during
the stream's close method.monitorTask
- (optional) task name to display during the close method.java.io.IOException
- writing is not supported, or attempting to write the file
failed, possibly due to permissions or remote disk full, etc.void writeFile(java.lang.String path, byte[] data) throws java.io.IOException
WalkRemoteObjectDatabase
This method attempts to perform as atomic of an update as it can, reducing (or eliminating) the time that clients might be able to see partial file content. This method is not suitable for very large transfers as the complete content must be passed as an argument.
Path may start with ../
to request writing of a file that
resides in the repository itself.
The requested path may or may not exist. If the path already exists as a file the file should be truncated and completely replaced.
This method creates any missing parent directories, if necessary.
writeFile
in class WalkRemoteObjectDatabase
path
- name of the file to write, relative to the current object
database.data
- complete new content of the file.java.io.IOException
- writing is not supported, or attempting to write the file
failed, possibly due to permissions or remote disk full, etc.private void mkdir_p(java.lang.String path) throws java.io.IOException
java.io.IOException
java.util.Map<java.lang.String,Ref> readAdvertisedRefs() throws TransportException
TransportException
private void readLooseRefs(java.util.TreeMap<java.lang.String,Ref> avail, java.lang.String dir, java.lang.String prefix) throws TransportException
TransportException
private Ref readRef(java.util.TreeMap<java.lang.String,Ref> avail, java.lang.String path, java.lang.String name) throws TransportException
TransportException
private Ref.Storage loose(Ref r)
void close()
WalkRemoteObjectDatabase
If the remote repository is contacted by a network socket this method must close that network socket, disconnecting the two peers. If the remote repository is actually local (same system) this method must close any open file handles used to read the "remote" repository.
close
in class WalkRemoteObjectDatabase