public class FileSystemStorage extends Object implements Storage
Information about the collection of files in a torrent is stored as a list of strings in the torrent metainfo. This makes it possible for malicious parties to create torrents with malformed pathnames, e.g. by using relative paths (. and ..), empty and invalid directory and file names, etc. In the worst case this can lead to loss and corruption of user data and execution of arbitrary code.
This storage implementation performs normalization of file paths, ensuring that:
FileSystemStorage(File)
)Algorithm for resolving paths:
1) The following transformations are applied to each individual path element:
File.separator
as the delimiter.
Examples:
"a/b/c" => "a/b/c"
" a/ b /c" => "a/b/c"
".a/.b" => ".a/.b"
"a./.b." => "a/.b"
"" => "_"
"a//b" => "a/_/b"
"." => "_"
".." => "_"
"/" => "_/_"
"/a/b/c" => "_/a/b/c"
Constructor and Description |
---|
FileSystemStorage(File rootDirectory)
Create a file-system based storage inside a given directory.
|
FileSystemStorage(Path rootDirectory) |
FileSystemStorage(Path rootDirectory,
int maxOpenFiles)
Construct a new FileSystemStorage
|
Modifier and Type | Method and Description |
---|---|
void |
flush()
Flushes any buffered data in this storage backend
|
StorageUnit |
getUnit(Torrent torrent,
TorrentFile torrentFile)
Get a storage unit for a particular torrent file.
|
public FileSystemStorage(File rootDirectory)
rootDirectory
- Root directory for this storage. All torrent files will be stored inside this directory.public FileSystemStorage(Path rootDirectory)
public FileSystemStorage(Path rootDirectory, int maxOpenFiles)
rootDirectory
- the root directory to store filesmaxOpenFiles
- the max number of open files this storage can use for efficiencypublic StorageUnit getUnit(Torrent torrent, TorrentFile torrentFile)
Storage
Copyright © 2016–2021. All rights reserved.