Skip to content

Commit

Permalink
Add attribute for trashed files.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Jan 23, 2025
1 parent 3807a4c commit efa099b
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected PathAttributes toAttributes(final Folder f) {
attrs.setCreationDate(f.getContentCreatedAt().getMillis());
}
if(f.getTrashedAt() != null) {
attrs.setHidden(true);
attrs.setTrashed(true);
}
attrs.setSize(f.getSize());
attrs.setFileId(f.getId());
Expand Down
19 changes: 19 additions & 0 deletions core/src/main/java/ch/cyberduck/core/PathAttributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,17 @@ public class PathAttributes extends Attributes implements Serializable {
* Should be hidden in the browser by default
*/
private Boolean duplicate;

/**
* Hidden flag set on server
*/
private Boolean hidden;

/**
* Trashed
*/
private Boolean trashed;

/**
* Revision number
*/
Expand Down Expand Up @@ -597,6 +603,19 @@ public PathAttributes withHidden(final boolean hidden) {
return this;
}

public Boolean isTrashed() {
return trashed != null && trashed;
}

public void setTrashed(final boolean trashed) {
this.trashed = trashed;
}

public PathAttributes withTrashed(final boolean trashed) {
this.setTrashed(trashed);
return this;
}

public Map<String, String> getMetadata() {
return metadata;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public boolean test(final Path f) {
// Filter previous versions and delete markers when searching for no specific version
return false;
}
if(f.attributes().isTrashed()) {
// Filter trashed files
return false;
}
switch(sensitivity) {
case sensitive:
return new CaseSensitivePathPredicate(file).test(f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public boolean accept(final Path file) {
if(file.attributes().isHidden()) {
return false;
}
if(file.attributes().isTrashed()) {
return false;
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public AttributedList<Path> list(final Path directory, final ListProgressListene
@Override
public boolean test(final Path f) {
// Exclude trashed
return super.test(f) && !f.attributes().isHidden();
return super.test(f) && !f.attributes().isTrashed();
}
}).size() > 1));
listener.chunk(directory, children);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public PathAttributes toAttributes(final File f) {
if(null != f.getTrashed()) {
if(f.getTrashed()) {
// Mark as hidden
attributes.setHidden(true);
attributes.setTrashed(true);
}
}
if(null != f.getSize()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void delete(final Map<Path, TransferStatus> files, final PasswordCallback
.queue(batch, new DeleteBatchCallback<>(f, failures, callback));
}
else {
if(f.attributes().isHidden()) {
if(f.attributes().isTrashed()) {
log.warn("Delete file {} already in trash", f);
new DriveBatchDeleteFeature(session, fileid).queue(f, batch, callback, failures);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Path mkdir(final Path folder, final TransferStatus status) throws Backgro
}
else {
try {
if(!new DriveAttributesFinderFeature(session, fileid).find(folder).isHidden()) {
if(!new DriveAttributesFinderFeature(session, fileid).find(folder).isTrashed()) {
throw new ConflictException(folder.getAbsolute());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ public String getFileId(final Path file) throws BackgroundException {
query = file;
}
final AttributedList<Path> list = new FileidDriveListService(session, this, query).list(file.getParent(), new DisabledListProgressListener());
final Path found = list.filter(new IgnoreTrashedComparator()).find(new SimplePathPredicate(file));
final Path found = list.filter(new TrashedComparator()).find(new SimplePathPredicate(file));
if(null == found) {
throw new NotfoundException(file.getAbsolute());
}
return this.cache(file, found.attributes().getFileId());
}

private static final class IgnoreTrashedComparator implements Comparator<Path> {
private static final class TrashedComparator implements Comparator<Path> {
@Override
public int compare(final Path o1, final Path o2) {
return Boolean.compare(o1.attributes().isHidden(), o2.attributes().isDuplicate());
return Boolean.compare(o1.attributes().isTrashed(), o2.attributes().isTrashed());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public DriveTouchFeature(final DriveSession session, final DriveFileIdProvider f
public Path touch(final Path file, final TransferStatus status) throws BackgroundException {
try {
try {
if(!new DriveAttributesFinderFeature(session, fileid).find(file).isHidden()) {
if(!new DriveAttributesFinderFeature(session, fileid).find(file).isTrashed()) {
throw new ConflictException(file.getAbsolute());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void delete(final Map<Path, TransferStatus> files, final PasswordCallback
session.getClient().teamdrives().delete(fileid.getFileId(f)).execute();
}
else {
if(f.attributes().isHidden()) {
if(f.attributes().isTrashed()) {
log.warn("Delete file {} already in trash", f);
new DriveDeleteFeature(session, fileid).delete(Collections.singletonList(f), prompt, callback);
continue;
Expand Down

0 comments on commit efa099b

Please sign in to comment.