[cli] Fix handling of delete file with stale colleciton entry (#1259)

## Description

## Tests
Tested locally
This commit is contained in:
Neeraj Gupta 2024-03-30 14:14:03 +05:30 committed by GitHub
parent fc5d8aeca6
commit a51a965fc8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 4 deletions

View file

@ -18,6 +18,10 @@ type File struct {
Info *FileInfo `json:"info,omitempty"` Info *FileInfo `json:"info,omitempty"`
} }
func (f File) IsRemovedFromAlbum() bool {
return f.IsDeleted || f.File.EncryptedData == "-"
}
// FileInfo has information about storage used by the file & it's metadata(future) // FileInfo has information about storage used by the file & it's metadata(future)
type FileInfo struct { type FileInfo struct {
FileSize int64 `json:"fileSize,omitempty"` FileSize int64 `json:"fileSize,omitempty"`

View file

@ -73,7 +73,7 @@ func MapCollectionToAlbum(ctx context.Context, collection api.Collection, holder
} }
func MapApiFileToPhotoFile(ctx context.Context, album model.RemoteAlbum, file api.File, holder *secrets.KeyHolder) (*model.RemoteFile, error) { func MapApiFileToPhotoFile(ctx context.Context, album model.RemoteAlbum, file api.File, holder *secrets.KeyHolder) (*model.RemoteFile, error) {
if file.IsDeleted { if file.IsRemovedFromAlbum() {
return nil, errors.New("file is deleted") return nil, errors.New("file is deleted")
} }
albumKey := album.AlbumKey.MustDecrypt(holder.DeviceKey) albumKey := album.AlbumKey.MustDecrypt(holder.DeviceKey)

View file

@ -87,16 +87,16 @@ func (c *ClICtrl) fetchRemoteFiles(ctx context.Context) error {
if file.UpdationTime > maxUpdated { if file.UpdationTime > maxUpdated {
maxUpdated = file.UpdationTime maxUpdated = file.UpdationTime
} }
if isFirstSync && file.IsDeleted { if isFirstSync && file.IsRemovedFromAlbum() {
// on first sync, no need to sync delete markers // on first sync, no need to sync delete markers
continue continue
} }
albumEntry := model.AlbumFileEntry{AlbumID: album.ID, FileID: file.ID, IsDeleted: file.IsDeleted, SyncedLocally: false} albumEntry := model.AlbumFileEntry{AlbumID: album.ID, FileID: file.ID, IsDeleted: file.IsRemovedFromAlbum(), SyncedLocally: false}
putErr := c.UpsertAlbumEntry(ctx, &albumEntry) putErr := c.UpsertAlbumEntry(ctx, &albumEntry)
if putErr != nil { if putErr != nil {
return putErr return putErr
} }
if file.IsDeleted { if file.IsRemovedFromAlbum() {
continue continue
} }
photoFile, err := mapper.MapApiFileToPhotoFile(ctx, album, file, c.KeyHolder) photoFile, err := mapper.MapApiFileToPhotoFile(ctx, album, file, c.KeyHolder)