Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Handle collection tombstones in Rust and Go CLIs

Neeraj Guptae3ef59e4a906
diff --git a/cli/pkg/remote_sync.go b/cli/pkg/remote_sync.go
index 9656ae40af..0befb4d9c6 100644
--- a/cli/pkg/remote_sync.go
+++ b/cli/pkg/remote_sync.go
@@ -23,16 +23,35 @@ func (c *ClICtrl) fetchRemoteCollections(ctx context.Context) error {
}
maxUpdated := lastSyncTime
for _, collection := range collections {
- if lastSyncTime == 0 && collection.IsDeleted {
+ if collection.UpdationTime > maxUpdated {
+ maxUpdated = collection.UpdationTime
+ }
+ if collection.IsDeleted {
+ albumJSON, getErr := c.GetValue(ctx, model.RemoteAlbums, []byte(strconv.FormatInt(collection.ID, 10)))
+ if getErr != nil {
+ return getErr
+ }
+ if albumJSON == nil {
+ continue
+ }
+ var album model.RemoteAlbum
+ if unmarshalErr := json.Unmarshal(albumJSON, &album); unmarshalErr != nil {
+ return unmarshalErr
+ }
+ album.IsDeleted = true
+ album.LastUpdatedAt = collection.UpdationTime
+ if putErr := c.PutValue(ctx, model.RemoteAlbums, []byte(strconv.FormatInt(album.ID, 10)), encoding.MustMarshalJSON(album)); putErr != nil {
+ return putErr
+ }
+ if putErr := c.PutConfigValue(ctx, fmt.Sprintf(model.CollectionsFileSyncKeyFmt, album.ID), []byte("0")); putErr != nil {
+ return putErr
+ }
continue
}
album, mapErr := mapper.MapCollectionToAlbum(ctx, collection, c.KeyHolder)
if mapErr != nil {
return mapErr
}
- if album.LastUpdatedAt > maxUpdated {
- maxUpdated = album.LastUpdatedAt
- }
albumJson := encoding.MustMarshalJSON(album)
putErr := c.PutValue(ctx, model.RemoteAlbums, []byte(strconv.FormatInt(album.ID, 10)), albumJson)
if putErr != nil {
@@ -92,10 +111,6 @@ func (c *ClICtrl) fetchRemoteFiles(ctx context.Context) error {
if file.UpdationTime > maxUpdated {
maxUpdated = file.UpdationTime
}
- if isFirstSync && file.IsRemovedFromAlbum() {
- // A first sync has no local album entries to delete.
- continue
- }
albumEntry := model.AlbumFileEntry{AlbumID: album.ID, FileID: file.ID, IsDeleted: file.IsRemovedFromAlbum(), SyncedLocally: false}
putErr := c.UpsertAlbumEntry(ctx, &albumEntry)
if putErr != nil {
diff --git a/cli/pkg/remote_to_disk_album.go b/cli/pkg/remote_to_disk_album.go
index fdd715b31c..9a5c62bee0 100644
--- a/cli/pkg/remote_to_disk_album.go
+++ b/cli/pkg/remote_to_disk_album.go
@@ -26,10 +26,11 @@ func (c *ClICtrl) createLocalFolderForRemoteAlbums(ctx context.Context, account
}
filter := ctx.Value(model.FilterKey).(model.Filter)
for _, album := range albums {
- if filter.SkipAlbum(album, false) {
- continue
- }
if album.IsDeleted {
+ if (filter.ExcludeShared && album.IsShared) ||
+ (filter.ExcludeHidden && album.IsHidden()) {
+ continue
+ }
if meta, ok := albumIDToMetaMap[album.ID]; ok {
log.Printf("Deleting album %s as it is deleted", meta.AlbumName)
if err = os.RemoveAll(filepath.Join(path, meta.FolderName)); err != nil {
@@ -39,6 +40,9 @@ func (c *ClICtrl) createLocalFolderForRemoteAlbums(ctx context.Context, account
}
continue
}
+ if filter.SkipAlbum(album, false) {
+ continue
+ }
metaByID := albumIDToMetaMap[album.ID]
if metaByID != nil && strings.EqualFold(metaByID.AlbumName, album.AlbumName) &&
diff --git a/cli/pkg/remote_to_disk_file.go b/cli/pkg/remote_to_disk_file.go
index 3f1c953e70..5eec8519b7 100644
--- a/cli/pkg/remote_to_disk_file.go
+++ b/cli/pkg/remote_to_disk_file.go
@@ -31,7 +31,7 @@ func (c *ClICtrl) syncFiles(ctx context.Context, account model.Account) error {
return readAlbumErr
}
for _, album := range remoteAlbums {
- if !album.IsDeleted && filter.SkipAlbum(album, false) {
+ if filter.SkipAlbum(album, false) {
albumsToSkip[album.ID] = true
}
}
diff --git a/rust/apps/cli/src/api/models.rs b/rust/apps/cli/src/api/models.rs
index d393007def..bc9546defb 100644
--- a/rust/apps/cli/src/api/models.rs
+++ b/rust/apps/cli/src/api/models.rs
@@ -329,7 +329,6 @@ pub struct Collection {
pub name_decryption_nonce: Option<String>,
#[serde(rename = "type")]
pub collection_type: String,
- pub attributes: Option<CollectionAttributes>,
pub sharees: Option<Vec<CollectionUser>>,
#[serde(rename = "publicURLs")]
pub public_urls: Option<Vec<PublicUrl>>,
@@ -342,11 +341,6 @@ pub struct Collection {
pub app: Option<String>,
}
-#[derive(Debug, Deserialize, Serialize, Clone)]
-pub struct CollectionAttributes {
- pub version: i32,
-}
-
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PublicUrl {