Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Working proof of concept for #223
Browse files Browse the repository at this point in the history
  • Loading branch information
binwiederhier committed Sep 11, 2014
1 parent b79a96a commit 3747c90
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
19 changes: 18 additions & 1 deletion syncany-cli/src/main/java/org/syncany/cli/DownCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,23 @@
import joptsimple.OptionSpec;

import org.syncany.operations.ChangeSet;
import org.syncany.operations.daemon.LocalEventBus;
import org.syncany.operations.daemon.messages.WatchEventResponse;
import org.syncany.operations.down.DownOperationOptions;
import org.syncany.operations.down.DownOperationOptions.DownConflictStrategy;
import org.syncany.operations.down.DownOperationResult;
import org.syncany.operations.down.DownOperationResult.DownResultCode;

import com.google.common.eventbus.Subscribe;

public class DownCommand extends Command {
private LocalEventBus eventBus;

public DownCommand() {
this.eventBus = LocalEventBus.getInstance();
this.eventBus.register(this);
}

@Override
public CommandScope getRequiredCommandScope() {
return CommandScope.INITIALIZED_LOCALDIR;
Expand Down Expand Up @@ -108,6 +119,12 @@ public void printResults(DownOperationResult operationResult) {
else {
out.println("Sync down skipped, no remote changes.");
}

}

@Subscribe
public void onWatchEventReceived(WatchEventResponse watchEventResponse) {
if ("DOWNLOAD_FILE".equals(watchEventResponse.getAction())) {
out.print("Downloading " + watchEventResponse.getSubject() + " ...\r");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.apache.commons.io.IOUtils;
import org.syncany.config.Config;
import org.syncany.database.MultiChunkEntry.MultiChunkId;
import org.syncany.operations.daemon.LocalEventBus;
import org.syncany.operations.daemon.messages.WatchEventResponse;
import org.syncany.plugins.StorageException;
import org.syncany.plugins.transfer.TransferManager;
import org.syncany.plugins.transfer.files.MultiChunkRemoteFile;
Expand All @@ -45,10 +47,12 @@ public class Downloader {

private Config config;
private TransferManager transferManager;
private LocalEventBus eventBus;

public Downloader(Config config, TransferManager transferManager) {
this.config = config;
this.transferManager = transferManager;
this.eventBus = LocalEventBus.getInstance();
}

/**
Expand All @@ -67,6 +71,8 @@ public void downloadAndDecryptMultiChunks(Set<MultiChunkId> unknownMultiChunkIds
logger.log(Level.INFO, " + Decrypted multichunk exists locally " + multiChunkId + ". No need to download it!");
}
else {
eventBus.post(new WatchEventResponse(config.getLocalDir().getAbsolutePath(), "DOWNLOAD_FILE", remoteMultiChunkFile.getName()));

logger.log(Level.INFO, " + Downloading multichunk " + multiChunkId + " ...");
transferManager.download(remoteMultiChunkFile, localEncryptedMultiChunkFile);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ public WatchEventResponse(String root, String action, String subject) {
this.action = action;
this.subject = subject;
}

public String getAction() {
return action;
}

public String getSubject() {
return subject;
}
}

0 comments on commit 3747c90

Please sign in to comment.