@@ -156,7 +156,7 @@ public void uploadFile(java.io.File file, String location) throws IOException {
156156 try {
157157 resetRanges ();
158158 String destinationRoot = normalizePath (ConfigParser .getConfig ().backupStorage .remoteDirectory );
159- String destinationPath = destinationRoot + '/' + location ;
159+ String destinationPath = concatPath ( destinationRoot , location ) ;
160160 FQID destinationId = createPath (destinationPath );
161161 Request request = new Request .Builder ()
162162 .addHeader ("Authorization" , "Bearer " + accessToken )
@@ -254,6 +254,23 @@ private String normalizePath(String path) {
254254 return normalized .substring (1 );
255255 }
256256
257+ /**
258+ * joins the two paths with '/' while handling emptiness of either side
259+ * @param lhs
260+ * @param rhs
261+ * @return joined path
262+ */
263+ @ NotNull
264+ private String concatPath (@ NotNull String lhs , @ NotNull String rhs ) {
265+ if (rhs .isEmpty ()) {
266+ return lhs ;
267+ }
268+ if (lhs .isEmpty ()) {
269+ return rhs ;
270+ }
271+ return lhs + '/' + rhs ;
272+ }
273+
257274 /**
258275 * creates all folders in the path if they don't already exist
259276 * @param path to create the folders for
@@ -343,9 +360,10 @@ private FQID createRootFolder(String folder) throws IOException {
343360 @ Nullable
344361 private FQID getRootFolder (String folder ) {
345362 try {
363+ String folderUrl = folder .isEmpty () ? folder : ":/" + folder ;
346364 Request request = new Request .Builder ()
347365 .addHeader ("Authorization" , "Bearer " + accessToken )
348- .url ("https://graph.microsoft.com/v1.0/me/drive/root:/ " + folder + "?$select=id,parentReference,remoteItem" )
366+ .url ("https://graph.microsoft.com/v1.0/me/drive/root" + folderUrl + "?$select=id,parentReference,remoteItem" )
349367 .build ();
350368 JSONObject parsedResponse ;
351369 try (Response response = DriveBackup .httpClient .newCall (request ).execute ()) {
0 commit comments