Skip to content
Snippets Groups Projects
Commit 105aa6f0 authored by kaloyane's avatar kaloyane
Browse files

minor: use java.net.URI to simplify FTP path normalization

SVN: 23908
parent 9d18bea1
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,8 @@ import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
......@@ -31,7 +33,6 @@ import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.ftplet.FtpFile;
import org.apache.log4j.Logger;
import ch.systemsx.cisd.cifex.client.application.utils.StringUtils;
import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory;
import ch.systemsx.cisd.openbis.generic.shared.IETLLIMSService;
......@@ -154,32 +155,21 @@ public class DSSFileSystemView implements FileSystemView
private String normalizePath(String path) throws FtpException
{
String result = path.trim();
if (result.startsWith(".."))
{
String currentPath = workingDirectory.getAbsolutePath();
int idx = currentPath.lastIndexOf(FtpConstants.FILE_SEPARATOR);
result = currentPath.substring(0, idx) + result.substring(2);
} else if (result.startsWith("."))
{
result = workingDirectory.getAbsolutePath() + result.substring(1);
} else if (false == result.startsWith(FtpConstants.ROOT_DIRECTORY))
String fullPath = path.trim();
if (false == fullPath.startsWith(FtpConstants.FILE_SEPARATOR))
{
result = workingDirectory.getAbsolutePath() + FtpConstants.FILE_SEPARATOR + result;
fullPath = workingDirectory.getAbsolutePath() + FtpConstants.FILE_SEPARATOR + fullPath;
}
// remove '.' at the end of a path
result = result.replaceAll("/\\.$", "/");
// remove trailing slashes
result = result.replaceAll("/*$", "");
// replace multiple adjacent slashes with a single slash
result = result.replaceAll("/+", "/");
if (StringUtils.isBlank(result))
try
{
URI uri = new URI(fullPath);
return uri.normalize().toString();
} catch (URISyntaxException ex)
{
return FtpConstants.ROOT_DIRECTORY;
throw new FtpException("Cannot parse path " + fullPath, ex);
}
return result;
}
public FtpFile getHomeDirectory() throws FtpException
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment