mirror of
https://github.com/Luzifer/cloudbox.git
synced 2024-12-23 03:01:18 +00:00
Add special case: File added locally and remotely
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
c658048ad1
commit
59e3c459a5
2 changed files with 45 additions and 1 deletions
|
@ -1,11 +1,52 @@
|
||||||
package sync
|
package sync
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/Luzifer/cloudbox/providers"
|
"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 {
|
func (s *Sync) deleteFile(on providers.CloudProvider, fileName string) error {
|
||||||
if err := on.DeleteFile(fileName); err != nil {
|
if err := on.DeleteFile(fileName); err != nil {
|
||||||
return errors.Wrap(err, "Unable to delete file")
|
return errors.Wrap(err, "Unable to delete file")
|
||||||
|
|
|
@ -21,7 +21,10 @@ func (s *Sync) decideAction(syncState *state, fileName string) error {
|
||||||
case change.HasAll(ChangeLocalAdd, ChangeRemoteAdd):
|
case change.HasAll(ChangeLocalAdd, ChangeRemoteAdd):
|
||||||
// Special case: Both are added, check they are the same file or leave this to manual resolve
|
// 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")
|
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):
|
case change.HasAll(ChangeLocalDelete, ChangeRemoteDelete):
|
||||||
// Special case: Both vanished, we just need to clean up the sync cache
|
// Special case: Both vanished, we just need to clean up the sync cache
|
||||||
|
|
Loading…
Reference in a new issue