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

Commit

Permalink
Fixing move used in deletion to not fail if original did not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
pimotte committed Aug 14, 2014
1 parent 42f32c5 commit b9a500c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Syncany, www.syncany.org
* Copyright (C) 2011-2014 Philipp C. Heckel <philipp.heckel@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.syncany.plugins;

/**
* @author pim-arch
*
*/
public class StorageMoveException extends StorageException {
private static final long serialVersionUID = 8929643336708862710L;

public StorageMoveException(Throwable cause) {
super(cause);
}

public StorageMoveException(String message, Throwable cause) {
super(message, cause);
}

public StorageMoveException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.commons.io.FileExistsException;
import org.apache.commons.io.FileUtils;
import org.syncany.plugins.StorageException;
import org.syncany.plugins.StorageMoveException;
import org.syncany.plugins.transfer.AbstractTransferManager;
import org.syncany.plugins.transfer.TransferManager;
import org.syncany.plugins.transfer.files.ActionRemoteFile;
Expand Down Expand Up @@ -145,6 +146,10 @@ public void move(RemoteFile sourceFile, RemoteFile targetFile) throws StorageExc

File sourceRemoteFile = getRemoteFile(sourceFile);
File targetRemoteFile = getRemoteFile(targetFile);

if (!sourceRemoteFile.exists()) {
throw new StorageMoveException("Unable to move file " + sourceFile + " because it does not exist.");
}

try {
FileUtils.moveFile(sourceRemoteFile, targetRemoteFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.simpleframework.xml.core.Persister;
import org.syncany.config.Config;
import org.syncany.plugins.StorageException;
import org.syncany.plugins.StorageMoveException;
import org.syncany.plugins.transfer.files.RemoteFile;
import org.syncany.plugins.transfer.files.TempRemoteFile;
import org.syncany.plugins.transfer.files.TransactionRemoteFile;
Expand Down Expand Up @@ -114,7 +115,12 @@ public void commit() throws StorageException {
else if (action.getType().equals(ActionTO.TYPE_DELETE)) {
RemoteFile remoteFile = action.getRemoteFile();
logger.log(Level.INFO, "- Moving {0} to temp. file {1} ...", new Object[] { remoteFile, tempRemoteFile });
transferManager.move(remoteFile, tempRemoteFile);
try {
transferManager.move(remoteFile, tempRemoteFile);
}
catch (StorageMoveException e) {
logger.log(Level.INFO, "- Move to delete file failed because the remoteFile does not exist.", e);
}
}
}

Expand Down

0 comments on commit b9a500c

Please sign in to comment.