mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-06 00:03:38 +00:00
Add caching to network drives
This commit is contained in:
@@ -76,7 +76,7 @@ func (manager *BackupManager) SetupSnapshotCache(storageName string) bool {
|
|||||||
preferencePath := GetDuplicacyPreferencePath()
|
preferencePath := GetDuplicacyPreferencePath()
|
||||||
cacheDir := path.Join(preferencePath, "cache", storageName)
|
cacheDir := path.Join(preferencePath, "cache", storageName)
|
||||||
|
|
||||||
storage, err := CreateFileStorage(cacheDir, 2, 1)
|
storage, err := CreateFileStorage(cacheDir, 2, false, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LOG_ERROR("BACKUP_CACHE", "Failed to create the snapshot cache dir: %v", err)
|
LOG_ERROR("BACKUP_CACHE", "Failed to create the snapshot cache dir: %v", err)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -19,19 +19,24 @@ type FileStorage struct {
|
|||||||
RateLimitedStorage
|
RateLimitedStorage
|
||||||
|
|
||||||
minimumLevel int // The minimum level of directories to dive into before searching for the chunk file.
|
minimumLevel int // The minimum level of directories to dive into before searching for the chunk file.
|
||||||
|
isCacheNeeded bool // Network storages require caching
|
||||||
storageDir string
|
storageDir string
|
||||||
numberOfThreads int
|
numberOfThreads int
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateFileStorage creates a file storage.
|
// CreateFileStorage creates a file storage.
|
||||||
func CreateFileStorage(storageDir string, minimumLevel int, threads int) (storage *FileStorage, err error) {
|
func CreateFileStorage(storageDir string, minimumLevel int, isCacheNeeded bool, threads int) (storage *FileStorage, err error) {
|
||||||
|
|
||||||
var stat os.FileInfo
|
var stat os.FileInfo
|
||||||
|
|
||||||
stat, err = os.Stat(storageDir)
|
stat, err = os.Stat(storageDir)
|
||||||
if os.IsNotExist(err) {
|
if err != nil {
|
||||||
err = os.MkdirAll(storageDir, 0744)
|
if os.IsNotExist(err) {
|
||||||
if err != nil {
|
err = os.MkdirAll(storageDir, 0744)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -47,6 +52,7 @@ func CreateFileStorage(storageDir string, minimumLevel int, threads int) (storag
|
|||||||
storage = &FileStorage {
|
storage = &FileStorage {
|
||||||
storageDir : storageDir,
|
storageDir : storageDir,
|
||||||
minimumLevel: minimumLevel,
|
minimumLevel: minimumLevel,
|
||||||
|
isCacheNeeded: isCacheNeeded,
|
||||||
numberOfThreads: threads,
|
numberOfThreads: threads,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +248,7 @@ func (storage *FileStorage) UploadFile(threadIndex int, filePath string, content
|
|||||||
|
|
||||||
// If a local snapshot cache is needed for the storage to avoid downloading/uploading chunks too often when
|
// If a local snapshot cache is needed for the storage to avoid downloading/uploading chunks too often when
|
||||||
// managing snapshots.
|
// managing snapshots.
|
||||||
func (storage *FileStorage) IsCacheNeeded () (bool) { return false }
|
func (storage *FileStorage) IsCacheNeeded () (bool) { return storage.isCacheNeeded }
|
||||||
|
|
||||||
// If the 'MoveFile' method is implemented.
|
// If the 'MoveFile' method is implemented.
|
||||||
func (storage *FileStorage) IsMoveFileImplemented() (bool) { return true }
|
func (storage *FileStorage) IsMoveFileImplemented() (bool) { return true }
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor
|
|||||||
storageURL := preference.StorageURL
|
storageURL := preference.StorageURL
|
||||||
|
|
||||||
isFileStorage := false
|
isFileStorage := false
|
||||||
|
isCacheNeeded := false
|
||||||
|
|
||||||
if strings.HasPrefix(storageURL, "/") {
|
if strings.HasPrefix(storageURL, "/") {
|
||||||
isFileStorage = true
|
isFileStorage = true
|
||||||
@@ -140,11 +141,12 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor
|
|||||||
|
|
||||||
if !isFileStorage && strings.HasPrefix(storageURL, `\\`) {
|
if !isFileStorage && strings.HasPrefix(storageURL, `\\`) {
|
||||||
isFileStorage = true
|
isFileStorage = true
|
||||||
|
isCacheNeeded = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if isFileStorage {
|
if isFileStorage {
|
||||||
fileStorage, err := CreateFileStorage(storageURL, 2, threads)
|
fileStorage, err := CreateFileStorage(storageURL, 2, isCacheNeeded, threads)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LOG_ERROR("STORAGE_CREATE", "Failed to load the file storage at %s: %v", storageURL, err)
|
LOG_ERROR("STORAGE_CREATE", "Failed to load the file storage at %s: %v", storageURL, err)
|
||||||
return nil
|
return nil
|
||||||
@@ -153,7 +155,16 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(storageURL, "flat://") {
|
if strings.HasPrefix(storageURL, "flat://") {
|
||||||
fileStorage, err := CreateFileStorage(storageURL, 0, threads)
|
fileStorage, err := CreateFileStorage(storageURL[7:], 0, false, threads)
|
||||||
|
if err != nil {
|
||||||
|
LOG_ERROR("STORAGE_CREATE", "Failed to load the file storage at %s: %v", storageURL, err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fileStorage
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(storageURL, "samba://") {
|
||||||
|
fileStorage, err := CreateFileStorage(storageURL[8:], 2, true, threads)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LOG_ERROR("STORAGE_CREATE", "Failed to load the file storage at %s: %v", storageURL, err)
|
LOG_ERROR("STORAGE_CREATE", "Failed to load the file storage at %s: %v", storageURL, err)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func init() {
|
|||||||
func loadStorage(localStoragePath string, threads int) (Storage, error) {
|
func loadStorage(localStoragePath string, threads int) (Storage, error) {
|
||||||
|
|
||||||
if testStorageName == "" || testStorageName == "file" {
|
if testStorageName == "" || testStorageName == "file" {
|
||||||
return CreateFileStorage(localStoragePath, 2, threads)
|
return CreateFileStorage(localStoragePath, 2, false, threads)
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := ioutil.ReadFile("test_storage.conf")
|
config, err := ioutil.ReadFile("test_storage.conf")
|
||||||
@@ -62,7 +62,9 @@ func loadStorage(localStoragePath string, threads int) (Storage, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if testStorageName == "flat" {
|
if testStorageName == "flat" {
|
||||||
return CreateFileStorage(localStoragePath, 0, threads)
|
return CreateFileStorage(localStoragePath, 0, false, threads)
|
||||||
|
} else if testStorageName == "samba" {
|
||||||
|
return CreateFileStorage(localStoragePath, 2, true, threads)
|
||||||
} else if testStorageName == "sftp" {
|
} else if testStorageName == "sftp" {
|
||||||
port, _ := strconv.Atoi(storage["port"])
|
port, _ := strconv.Atoi(storage["port"])
|
||||||
return CreateSFTPStorageWithPassword(storage["server"], port, storage["username"], storage["directory"], storage["password"], threads)
|
return CreateSFTPStorageWithPassword(storage["server"], port, storage["username"], storage["directory"], storage["password"], threads)
|
||||||
|
|||||||
Reference in New Issue
Block a user