Skip to content

Commit

Permalink
Merge pull request #2293 in ITERATE/cyberduck from bugfix/TRAC-10654 …
Browse files Browse the repository at this point in the history
…to master

* commit 'afb3b30e74960d18f1ac0bd6d18170f6f9cc3a67':
  Revert "Review implementation to not use cache."
  Fix tests.
  Fix #10654.
  Review implementation to not use cache.
  • Loading branch information
automerge committed Jan 26, 2021
2 parents 10a04f4 + afb3b30 commit 4788f07
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
Expand Up @@ -23,6 +23,7 @@
import ch.cyberduck.core.Path;
import ch.cyberduck.core.PathAttributes;
import ch.cyberduck.core.PathContainerService;
import ch.cyberduck.core.SimplePathPredicate;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.exception.NotfoundException;
import ch.cyberduck.core.features.AttributesFinder;
Expand Down Expand Up @@ -71,7 +72,7 @@ public PathAttributes find(final Path file) throws BackgroundException {
query = file;
}
final AttributedList<Path> list = new FileidDriveListService(session, fileid, query).list(file.getParent(), new DisabledListProgressListener());
final Path found = list.find(new DriveFileidProvider.IgnoreTrashedPathPredicate(file));
final Path found = list.find(new SimplePathPredicate(file));
if(null == found) {
throw new NotfoundException(file.getAbsolute());
}
Expand Down
Expand Up @@ -52,7 +52,7 @@ public String getFileid(final Path file, final ListProgressListener listener) th
}
if(cache.isCached(file.getParent())) {
final AttributedList<Path> list = cache.get(file.getParent());
final Path found = list.find(new IgnoreTrashedPathPredicate(file));
final Path found = list.find(new SimplePathPredicate(file));
if(null != found) {
if(StringUtils.isNotBlank(found.attributes().getVersionId())) {
return this.set(file, found.attributes().getVersionId());
Expand All @@ -76,7 +76,7 @@ public String getFileid(final Path file, final ListProgressListener listener) th
query = file;
}
final AttributedList<Path> list = new FileidDriveListService(session, this, query).list(file.getParent(), new DisabledListProgressListener());
final Path found = list.find(new IgnoreTrashedPathPredicate(file));
final Path found = list.find(new SimplePathPredicate(file));
if(null == found) {
throw new NotfoundException(file.getAbsolute());
}
Expand Down
Expand Up @@ -30,7 +30,8 @@
import java.util.EnumSet;
import java.util.UUID;

import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

@Category(IntegrationTest.class)
public class DriveDirectoryFeatureTest extends AbstractDriveTest {
Expand All @@ -43,11 +44,10 @@ public void testMkdir() throws Exception {
assertNotNull(test.attributes().getVersionId());
assertTrue(new DefaultFindFeature(session).find(test));
new DriveDeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(),
new Delete.DisabledCallback());
new Delete.DisabledCallback());
// Trashed
test.attributes().setVersionId(null);
assertFalse(new DriveFindFeature(session, fileid).find(test));
assertFalse(new DefaultFindFeature(session).find(test));
assertTrue(new DriveFindFeature(session, fileid).find(test));
assertTrue(new DefaultFindFeature(session).find(test));
assertTrue(new DefaultAttributesFinderFeature(session).find(test).isDuplicate());
}
}
Expand Up @@ -48,5 +48,7 @@ public void testFind() throws Exception {
new DriveTouchFeature(session, fileid).touch(file, new TransferStatus());
assertTrue(new DriveFindFeature(session, fileid).find(file));
new DriveDeleteFeature(session, fileid).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
assertTrue(new DriveFindFeature(session, fileid).find(file));
assertTrue(new DriveAttributesFinderFeature(session, fileid).find(file).isDuplicate());
}
}
Expand Up @@ -15,9 +15,11 @@
* GNU General Public License for more details.
*/

import ch.cyberduck.core.AlphanumericRandomStringService;
import ch.cyberduck.core.DisabledConnectionCallback;
import ch.cyberduck.core.DisabledListProgressListener;
import ch.cyberduck.core.DisabledLoginCallback;
import ch.cyberduck.core.DisabledPasswordCallback;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.PathAttributes;
import ch.cyberduck.core.PathCache;
Expand All @@ -26,6 +28,7 @@
import ch.cyberduck.core.features.Write;
import ch.cyberduck.core.http.HttpResponseOutputStream;
import ch.cyberduck.core.io.StreamCopier;
import ch.cyberduck.core.shared.DefaultAttributesFinderFeature;
import ch.cyberduck.core.shared.DefaultFindFeature;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.test.IntegrationTest;
Expand All @@ -39,7 +42,6 @@
import java.io.InputStream;
import java.util.Collections;
import java.util.EnumSet;
import java.util.UUID;

import static org.junit.Assert.*;

Expand All @@ -48,7 +50,7 @@ public class DriveWriteFeatureTest extends AbstractDriveTest {

@Test
public void testWrite() throws Exception {
final Path test = new Path(DriveHomeFinderService.MYDRIVE_FOLDER, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
final Path test = new Path(DriveHomeFinderService.MYDRIVE_FOLDER, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final DriveFileidProvider fileid = new DriveFileidProvider(session).withCache(cache);
{
final TransferStatus status = new TransferStatus();
Expand All @@ -57,7 +59,6 @@ public void testWrite() throws Exception {
status.setLength(content.length);
final HttpResponseOutputStream<VersionId> out = new DriveWriteFeature(session, fileid).write(test, status, new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
out.close();
assertNotNull(out.getStatus().id);
test.attributes().withVersionId(out.getStatus().id);
assertTrue(new DefaultFindFeature(session).find(test));
Expand All @@ -81,12 +82,24 @@ public void testWrite() throws Exception {
status.setLength(content.length);
final HttpResponseOutputStream<VersionId> out = new DriveWriteFeature(session, fileid).write(test, status, new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
out.close();
assertNotNull(out.getStatus().id);
final PathAttributes attributes = new DriveListService(session, fileid).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes();
assertEquals(content.length, attributes.getSize());
assertEquals("x-application/cyberduck", session.getClient().files().get(test.attributes().getVersionId()).execute().getMimeType());
}
new DriveDeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}

@Test
public void testWritePreviuoslyTrashed() throws Exception {
final DriveFileidProvider fileid = new DriveFileidProvider(session).withCache(cache);
final Path test = new DriveTouchFeature(session, fileid).touch(new Path(DriveHomeFinderService.MYDRIVE_FOLDER, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
new DriveDeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledPasswordCallback(), new Delete.DisabledCallback());
assertTrue(new DriveFindFeature(session, fileid).find(test));
assertTrue(new DriveAttributesFinderFeature(session, fileid).find(test).isDuplicate());
assertTrue(new DefaultFindFeature(session).find(test));
assertTrue(new DefaultAttributesFinderFeature(session).find(test).isDuplicate());
new DriveTouchFeature(session, fileid).touch(test, new TransferStatus());
new DriveDeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledPasswordCallback(), new Delete.DisabledCallback());
}
}

0 comments on commit 4788f07

Please sign in to comment.