1
0
Fork 0
mirror of https://github.com/Luzifer/cloudbox.git synced 2024-12-22 10:41:19 +00:00

Add special case: File added locally and remotely

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-06-16 23:30:26 +02:00
parent c658048ad1
commit 59e3c459a5
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 45 additions and 1 deletions

View file

@ -1,11 +1,52 @@
package sync
import (
"crypto/sha256"
"github.com/pkg/errors"
"github.com/Luzifer/cloudbox/providers"
)
func (s *Sync) addBothCreated(fileName string) error {
// Use forced sha256 to ensure lesser chance for collision
var hashMethod = sha256.New()
local, err := s.local.GetFile(fileName)
if err != nil {
return errors.Wrap(err, "Unable to retrieve file from local")
}
remote, err := s.remote.GetFile(fileName)
if err != nil {
return errors.Wrap(err, "Unable to retrieve file from remote")
}
localSum, err := local.Checksum(hashMethod)
if err != nil {
return errors.Wrap(err, "Unable to get checksum from local file")
}
remoteSum, err := remote.Checksum(hashMethod)
if err != nil {
return errors.Wrap(err, "Unable to get checksum from remote file")
}
if localSum != remoteSum {
return errors.New("Checksums differ")
}
if err := s.setDBFileInfo(sideLocal, local.Info()); err != nil {
return errors.Wrap(err, "Unable to update DB info for local file")
}
if err := s.setDBFileInfo(sideRemote, remote.Info()); err != nil {
return errors.Wrap(err, "Unable to update DB info for remote file")
}
return nil
}
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")

View file

@ -21,7 +21,10 @@ func (s *Sync) decideAction(syncState *state, fileName string) error {
case change.HasAll(ChangeLocalAdd, ChangeRemoteAdd):
// Special case: Both are added, check they are the same file or leave this to manual resolve
logger.Debug("File added locally as well as remotely")
// TODO: Handle special case
if err := s.addBothCreated(fileName); err != nil {
logger.WithError(err).Error("Unable to add locally as well as remotely added file")
}
case change.HasAll(ChangeLocalDelete, ChangeRemoteDelete):
// Special case: Both vanished, we just need to clean up the sync cache