Documentation ¶
Index ¶
- Variables
- func CalculateChecksum(pathToFile, algorithm string) (string, error)
- func ExchangeHome() (exchangeHome string, err error)
- func ExpandTilde(filePath string) (string, error)
- func FileExists(path string) bool
- func JsonFileToObject(absPath string, obj interface{}) error
- func LoadRelativeFile(relativePath string) ([]byte, error)
- func LooksSafeToDelete(dir string, minLength, minSeparators int) bool
- func RecursiveFileList(dir string) ([]string, error)
- func RelativeToAbsPath(relativePath string) (string, error)
- type FileSummary
- type FileSystemIterator
- type ReadIterator
- type TarFileIterator
- type TarReadCloser
Constants ¶
This section is empty.
Variables ¶
var MimeTypes = map[string]string{}/* 982 elements not displayed */
MimeTypes maps file extensions to known mime types. This list comes from https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types.
Functions ¶
func CalculateChecksum ¶
CalculateChecksum calculates the md5 or sha256 checksum of a file. Param pathToFile is the path the file, and algorithm should be one of constants.AlgMd5 or constante.AlgSha256. Returns the hex-encoded digest or an error.
func ExchangeHome ¶
ExchangeHome returns the absolute path to the exchange root directory, which contains source, config and test files. This will usually be something like /home/xxx/go/src/github.com/APTrust/exchange. You can set this explicitly by defining an environment variable called EXCHANGE_HOME. Otherwise, this function will try to infer the value by appending to the environment variable GOPATH. If neither of those variables is set, this returns an error.
func ExpandTilde ¶
Expands the tilde in a directory path to the current user's home directory. For example, on Linux, ~/data would expand to something like /home/josie/data
func FileExists ¶
Returns true if the file at path exists, false if not.
func JsonFileToObject ¶
Reads data from the file at absPath (an absolute path) and coverts it to an object of whatever type param obj is. Returns an error if there's a problem reading the file or unmarshalling the data into the type you passed in. On success, this returns nil and your object will contain the data from the file.
func LoadRelativeFile ¶
LoadRelativeFile reads the file at the specified path relative to EXCHANGE_HOME and returns the contents as a byte array.
func LooksSafeToDelete ¶
Returns true if the path specified by dir has at least minLength characters and at least minSeparators path separators. This is for testing paths you want pass into os.RemoveAll(), so you don't wind up deleting "/" or "/etc" or something catastrophic like that.
func RecursiveFileList ¶
RecursiveFileList returns a list of all files in path dir and its subfolders. It does not return directories.
func RelativeToAbsPath ¶
Converts a relative path within the exchange directory tree to an absolute path.
Types ¶
type FileSummary ¶
type FileSummary struct { RelPath string AbsPath string Mode os.FileMode Size int64 ModTime time.Time IsDir bool IsRegularFile bool Uid int Gid int }
FileSummary includes the intersection of the set of file attributes available from os.FileInfo and tar.Header.
type FileSystemIterator ¶
type FileSystemIterator struct {
// contains filtered or unexported fields
}
func NewFileSystemIterator ¶
func NewFileSystemIterator(pathToDir string) (*FileSystemIterator, error)
func (*FileSystemIterator) GetTopLevelDirNames ¶
func (iter *FileSystemIterator) GetTopLevelDirNames() []string
Returns the last component of the path that this iterator is traversing. That will be a slice of strings, with exactly one item. We return a slice instead of a string to maintain API compatibility with the ReadIterator interface.
func (*FileSystemIterator) Next ¶
func (iter *FileSystemIterator) Next() (io.ReadCloser, *FileSummary, error)
Returns an open reader for the next file, along with a FileSummary. Returns io.EOF when it reaches the last file. The caller is responsible for closing the reader.
type ReadIterator ¶
type ReadIterator interface { Next() (io.ReadCloser, *FileSummary, error) GetTopLevelDirNames() []string }
ReadIterator is an interface that allows TarFileIterator and FileSystemIterator to be used interchangeably.
type TarFileIterator ¶
type TarFileIterator struct {
// contains filtered or unexported fields
}
TarFileIterator lets us read tarred bags (or any other tarred files) without having to untar them.
func NewTarFileIterator ¶
func NewTarFileIterator(pathToTarFile string) (*TarFileIterator, error)
NewTarFileIterator returns a new TarFileIterator. Param pathToTarFile should be an absolute path to the tar file.
func (*TarFileIterator) Close ¶
func (iter *TarFileIterator) Close()
Close closes the underlying tar file.
func (*TarFileIterator) Find ¶
func (iter *TarFileIterator) Find(originalPathWithBagName string) (io.ReadCloser, error)
Find returns an open reader for the file with the specified name, or nil if that file cannot be found. Caller is responsible for closing the reader. Note that the iterator is forward-only, which makes it unsuitable for re-use. Create a new iterator each time you want to call Find, and user genericFile.OriginalPathWithBagName() to get the originalPath param.
func (*TarFileIterator) GetTopLevelDirNames ¶
func (iter *TarFileIterator) GetTopLevelDirNames() []string
GetTopLevelDirNames returns the names of the top level directories to which the tar file expands. For APTrust purposes, the tar file should expand to one directory whose name matches that of the tar file, minus the .tar extension. In reality, tar files can expand to multiple top-level directories with any names.
Note that you should read the entire tar file before calling this; otherwise, you may not get all the top-level dir names.
func (*TarFileIterator) Next ¶
func (iter *TarFileIterator) Next() (io.ReadCloser, *FileSummary, error)
Next returns an open reader for the next file, along with a FileSummary. Returns io.EOF when it reaches the last file.
type TarReadCloser ¶
type TarReadCloser struct {
// contains filtered or unexported fields
}
TarReaderCloser implements the io.ReadCloser interface.
func (TarReadCloser) Close ¶
func (tarReadCloser TarReadCloser) Close() error
Close is a no-op that pretends to close something that is not a file and does not need to be closed.