Search in sources :

Example 1 with TemporarySupportDirectoryFinder

use of ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder in project cyberduck by iterate-ch.

the class FileManagerTrashFeatureTest method testTrashNonEmpty.

@Test
public void testTrashNonEmpty() throws Exception {
    final Trash trash = new FileManagerTrashFeature();
    final SupportDirectoryFinder finder = new TemporarySupportDirectoryFinder();
    final Local temp = finder.find();
    final Local directory = LocalFactory.get(temp, UUID.randomUUID().toString());
    directory.mkdir();
    final Local sub = LocalFactory.get(directory, UUID.randomUUID().toString());
    sub.mkdir();
    final Local file = LocalFactory.get(sub, UUID.randomUUID().toString());
    final Touch touch = LocalTouchFactory.get();
    touch.touch(file);
    trash.trash(directory);
}
Also used : TemporarySupportDirectoryFinder(ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder) SupportDirectoryFinder(ch.cyberduck.core.preferences.SupportDirectoryFinder) Local(ch.cyberduck.core.Local) Touch(ch.cyberduck.core.local.features.Touch) Trash(ch.cyberduck.core.local.features.Trash) TemporarySupportDirectoryFinder(ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder) Test(org.junit.Test)

Example 2 with TemporarySupportDirectoryFinder

use of ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder in project cyberduck by iterate-ch.

the class FileManagerTrashFeatureTest method testTrashOpenFile.

@Test
public void testTrashOpenFile() throws Exception {
    final Trash trash = new FileManagerTrashFeature();
    final SupportDirectoryFinder finder = new TemporarySupportDirectoryFinder();
    final Local temp = finder.find();
    final Local directory = LocalFactory.get(temp, UUID.randomUUID().toString());
    directory.mkdir();
    final Local sub = LocalFactory.get(directory, UUID.randomUUID().toString());
    sub.mkdir();
    final Local file = LocalFactory.get(sub, UUID.randomUUID().toString());
    final Touch touch = LocalTouchFactory.get();
    touch.touch(file);
    try (final OutputStream stream = file.getOutputStream(false)) {
        trash.trash(directory);
    }
}
Also used : TemporarySupportDirectoryFinder(ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder) SupportDirectoryFinder(ch.cyberduck.core.preferences.SupportDirectoryFinder) OutputStream(java.io.OutputStream) Local(ch.cyberduck.core.Local) Touch(ch.cyberduck.core.local.features.Touch) Trash(ch.cyberduck.core.local.features.Trash) TemporarySupportDirectoryFinder(ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder) Test(org.junit.Test)

Example 3 with TemporarySupportDirectoryFinder

use of ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder in project cyberduck by iterate-ch.

the class WorkspaceTrashFeatureTest method testTrashNonEmpty.

@Test
public void testTrashNonEmpty() throws Exception {
    final Trash trash = new WorkspaceTrashFeature();
    final SupportDirectoryFinder finder = new TemporarySupportDirectoryFinder();
    final Local temp = finder.find();
    final Local directory = LocalFactory.get(temp, UUID.randomUUID().toString());
    directory.mkdir();
    final Local sub = LocalFactory.get(directory, UUID.randomUUID().toString());
    sub.mkdir();
    final Local file = LocalFactory.get(sub, UUID.randomUUID().toString());
    final Touch touch = LocalTouchFactory.get();
    touch.touch(file);
    trash.trash(directory);
}
Also used : TemporarySupportDirectoryFinder(ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder) SupportDirectoryFinder(ch.cyberduck.core.preferences.SupportDirectoryFinder) Local(ch.cyberduck.core.Local) Touch(ch.cyberduck.core.local.features.Touch) Trash(ch.cyberduck.core.local.features.Trash) TemporarySupportDirectoryFinder(ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder) Test(org.junit.Test)

Example 4 with TemporarySupportDirectoryFinder

use of ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder in project cyberduck by iterate-ch.

the class WorkspaceTrashFeatureTest method testTrashOpenFile.

@Test
public void testTrashOpenFile() throws Exception {
    final Trash trash = new WorkspaceTrashFeature();
    final SupportDirectoryFinder finder = new TemporarySupportDirectoryFinder();
    final Local temp = finder.find();
    final Local directory = LocalFactory.get(temp, UUID.randomUUID().toString());
    directory.mkdir();
    final Local sub = LocalFactory.get(directory, UUID.randomUUID().toString());
    sub.mkdir();
    final Local file = LocalFactory.get(sub, UUID.randomUUID().toString());
    final Touch touch = LocalTouchFactory.get();
    touch.touch(file);
    try (final OutputStream stream = file.getOutputStream(false)) {
        trash.trash(directory);
    }
}
Also used : TemporarySupportDirectoryFinder(ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder) SupportDirectoryFinder(ch.cyberduck.core.preferences.SupportDirectoryFinder) OutputStream(java.io.OutputStream) Local(ch.cyberduck.core.Local) Touch(ch.cyberduck.core.local.features.Touch) Trash(ch.cyberduck.core.local.features.Trash) TemporarySupportDirectoryFinder(ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder) Test(org.junit.Test)

Example 5 with TemporarySupportDirectoryFinder

use of ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder in project cyberduck by iterate-ch.

the class BrowserTableDataSource method namesOfPromisedFilesDroppedAtDestination.

/**
 * @return the names (not full paths) of the files that the receiver promises to create at dropDestination. This
 * method is invoked when the drop has been accepted by the destination and the destination, in the case of another
 * Cocoa application, invokes the NSDraggingInfo method namesOfPromisedFilesDroppedAtDestination. For long
 * operations, you can cache dropDestination and defer the creation of the files until the finishedDraggingImage
 * method to avoid blocking the destination application.
 */
@Override
public NSArray namesOfPromisedFilesDroppedAtDestination(final NSURL url) {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Return names of promised files dropped at %s", url));
    }
    NSMutableArray promisedDragNames = NSMutableArray.array();
    if (null != url) {
        final Local destination = LocalFactory.get(url.path());
        final DownloadFilterOptions options = new DownloadFilterOptions(controller.getSession().getHost());
        if (destination.isChild(new TemporarySupportDirectoryFinder().find())) {
            options.icon = false;
            options.segments = false;
        }
        final PathPasteboard pasteboard = controller.getPasteboard();
        final List<TransferItem> downloads = new ArrayList<TransferItem>();
        for (Path p : pasteboard) {
            downloads.add(new TransferItem(p, LocalFactory.get(destination, p.getName())));
            // Add to returned path names
            promisedDragNames.addObject(p.getName());
        }
        if (downloads.size() == 1) {
            if (downloads.iterator().next().remote.isFile()) {
                final Local file = downloads.iterator().next().local;
                if (!file.exists()) {
                    try {
                        LocalTouchFactory.get().touch(file);
                        if (options.icon) {
                            IconServiceFactory.get().set(file, new TransferStatus().withLength(0L));
                        }
                    } catch (AccessDeniedException e) {
                        log.warn(String.format("Failure creating file %s %s", file, e.getMessage()));
                    }
                }
            }
            if (downloads.iterator().next().remote.isDirectory()) {
                final Local file = downloads.iterator().next().local;
                if (!file.exists()) {
                    try {
                        new DefaultLocalDirectoryFeature().mkdir(file);
                    } catch (AccessDeniedException e) {
                        log.warn(e.getMessage());
                    }
                }
            }
        }
        // kTemporaryFolderType
        final boolean dock = destination.equals(LocalFactory.get("~/Library/Caches/TemporaryItems"));
        if (dock) {
            for (Path p : pasteboard) {
                // Drag to application icon in dock.
                controller.edit(p);
            }
        } else {
            final Transfer transfer = new DownloadTransfer(controller.getSession().getHost(), downloads).withOptions(options);
            controller.transfer(transfer, Collections.emptyList());
        }
        pasteboard.clear();
    }
    // Filenames
    return promisedDragNames;
}
Also used : Path(ch.cyberduck.core.Path) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) DownloadFilterOptions(ch.cyberduck.core.transfer.download.DownloadFilterOptions) ArrayList(java.util.ArrayList) Local(ch.cyberduck.core.Local) PathPasteboard(ch.cyberduck.core.pasteboard.PathPasteboard) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) NSMutableArray(ch.cyberduck.binding.foundation.NSMutableArray) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) DefaultLocalDirectoryFeature(ch.cyberduck.core.local.DefaultLocalDirectoryFeature) CopyTransfer(ch.cyberduck.core.transfer.CopyTransfer) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) TransferItem(ch.cyberduck.core.transfer.TransferItem) TemporarySupportDirectoryFinder(ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder)

Aggregations

Local (ch.cyberduck.core.Local)7 TemporarySupportDirectoryFinder (ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder)7 Touch (ch.cyberduck.core.local.features.Touch)6 Trash (ch.cyberduck.core.local.features.Trash)6 SupportDirectoryFinder (ch.cyberduck.core.preferences.SupportDirectoryFinder)6 Test (org.junit.Test)6 OutputStream (java.io.OutputStream)2 Path (java.nio.file.Path)2 NSMutableArray (ch.cyberduck.binding.foundation.NSMutableArray)1 Path (ch.cyberduck.core.Path)1 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)1 DefaultLocalDirectoryFeature (ch.cyberduck.core.local.DefaultLocalDirectoryFeature)1 PathPasteboard (ch.cyberduck.core.pasteboard.PathPasteboard)1 CopyTransfer (ch.cyberduck.core.transfer.CopyTransfer)1 DownloadTransfer (ch.cyberduck.core.transfer.DownloadTransfer)1 Transfer (ch.cyberduck.core.transfer.Transfer)1 TransferItem (ch.cyberduck.core.transfer.TransferItem)1 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)1 UploadTransfer (ch.cyberduck.core.transfer.UploadTransfer)1 DownloadFilterOptions (ch.cyberduck.core.transfer.download.DownloadFilterOptions)1