File dirDst = getExistingDir(getParam("dst"), FileActionEnum.READ);
if (dirDst != null) {
List<String> targets = (List<String>) getParamObject("targets[]");
if (targets == null || targets.isEmpty()) {
throw new ConnectorException("Invalid parameters");
}
boolean cut = "1".equals(getParam("cut"));
for (String targetHash : targets) {
File fileTarget = getExistingFile(targetHash, dirSrc, FileActionEnum.READ);
if (fileTarget == null) {
_content(dirCurrent, true);
throw new ConnectorException("File not found");
}
if (dirSrc.getAbsolutePath().equals(dirDst.getAbsolutePath())) {
_content(dirCurrent, true);
throw new ConnectorException("Unable to copy into itself");
}
File futureFile = getNewFile(basename(fileTarget), dirDst, FileActionEnum.WRITE);
if (cut) {
// moving file...
if (!getConfig()._isAllowedExistingFile(fileTarget, FileActionEnum.DELETE)) {
throw new ConnectorException("Access denied");
}
try {
getFs().renameFileOrDirectory(fileTarget, futureFile);
// TODO
// if (!is_dir($f)) {
// $this->_rmTmb($f);
// }
} catch (FsException e) {
_content(dirCurrent, true);
throw new ConnectorException("Unable to move files");
}
} else {
// copying file...
try {
getFs().copyFileOrDirectory(fileTarget, futureFile);
} catch (FsException e) {
_content(dirCurrent, true);
throw new ConnectorException("Unable to copy files");
}
}
}
}
}