From 85d7a7ec890288dd0c0d5d3584caea464ff76f3b Mon Sep 17 00:00:00 2001 From: kaloyane <kaloyane> Date: Fri, 27 May 2011 12:25:28 +0000 Subject: [PATCH] [LMS-2277]: fixed + tested on Windows SVN: 21493 --- .../shared/api/v1/FileInfoDssBuilder.java | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/FileInfoDssBuilder.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/FileInfoDssBuilder.java index 0f4e3dc4f1b..78051cd1302 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/FileInfoDssBuilder.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/v1/FileInfoDssBuilder.java @@ -29,9 +29,9 @@ import java.util.ArrayList; public class FileInfoDssBuilder { - private final String dataSetRoot; + private final File dataSetRootFile; - private final String listingRoot; + private final File listingRootFile; /** * Constructor for FileInfoDssFactory @@ -41,8 +41,8 @@ public class FileInfoDssBuilder */ public FileInfoDssBuilder(String dataSetRoot, String relativeRoot) { - this.dataSetRoot = dataSetRoot; - this.listingRoot = relativeRoot; + this.dataSetRootFile = new File(dataSetRoot); + this.listingRootFile = new File(relativeRoot); } /** @@ -100,11 +100,10 @@ public class FileInfoDssBuilder */ private String pathRelativeToDataSetRoot(File file) throws IOException { - String path; - path = file.getCanonicalPath(); - path = path.substring(dataSetRoot.length()); - return (path.length() > 0) ? path : "/"; - + String result = dataSetRootFile.toURI().relativize(file.toURI()).toString(); + // remove trailing slashes + result = result.replaceAll("/+$", ""); + return "/" + result; } /** @@ -112,14 +111,6 @@ public class FileInfoDssBuilder */ private String pathRelativeToListingRoot(File file) throws IOException { - String path; - path = file.getCanonicalPath(); - path = path.substring(listingRoot.length()); - if (path.startsWith("/")) - { - path = path.substring(1); - } - return (path.length() > 0) ? path : ""; - + return listingRootFile.toURI().relativize(file.toURI()).toString(); } } -- GitLab