mirror of
https://github.com/Luzifer/cloudbox.git
synced 2024-11-08 22:20:09 +00:00
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package sync
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/Luzifer/cloudbox/providers"
|
|
)
|
|
|
|
func (s *Sync) deleteFile(on providers.CloudProvider, fileName string) error {
|
|
if err := on.DeleteFile(fileName); err != nil {
|
|
return errors.Wrap(err, "Unable to delete file")
|
|
}
|
|
|
|
if err := s.deleteDBFileInfo(sideLocal, fileName); err != nil {
|
|
return errors.Wrap(err, "Umable to delete local file info")
|
|
}
|
|
|
|
if err := s.deleteDBFileInfo(sideRemote, fileName); err != nil {
|
|
return errors.Wrap(err, "Umable to delete remote file info")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *Sync) transferFile(from, to providers.CloudProvider, sideFrom, sideTo, fileName string) error {
|
|
file, err := from.GetFile(fileName)
|
|
if err != nil {
|
|
return errors.Wrap(err, "Unable to retrieve file")
|
|
}
|
|
|
|
newFile, err := to.PutFile(file)
|
|
if err != nil {
|
|
return errors.Wrap(err, "Unable to put file")
|
|
}
|
|
|
|
if err := s.setDBFileInfo(sideTo, newFile.Info()); err != nil {
|
|
return errors.Wrap(err, "Unable to update DB info for target file")
|
|
}
|
|
|
|
if err := s.setDBFileInfo(sideFrom, file.Info()); err != nil {
|
|
return errors.Wrap(err, "Unable to update DB info for source file")
|
|
}
|
|
|
|
return nil
|
|
}
|