From 34524bebbc2deb08e4780e72c4c1f0f63cb19fe1 Mon Sep 17 00:00:00 2001 From: rcmerci Date: Fri, 25 Nov 2022 17:37:18 +0800 Subject: [PATCH] fix(sync): s3 404 download caused by path-normalize when server side has a file with unnormalized-path, and client side doesn't have this file. we need to use unnormalized-path to download. this commit also ensure path & encrypted-path consistent (result of r first :path (not= filepath)) (-> r first :path))))) - (defn c (ipc/ipc "set-env" graph-uuid (if prod? "prod" "dev") private-key public-key))) - (c (ipc/ipc "get-local-all-files-meta" graph-uuid base-path))))] (if (instance? ExceptionInfo r) @@ -803,18 +802,26 @@ (->> r js->clj (map (fn [[path metadata]] - (->FileMetadata (get metadata "size") (get metadata "md5") (path-normalize path) - (get metadata "encryptedFname") (get metadata "mtime") false nil))) + (let [normalized-path (path-normalize path) + encryptedFname (if (not= path normalized-path) + (first (FileMetadata (get metadata "size") (get metadata "md5") normalized-path + encryptedFname (get metadata "mtime") false nil)))) set))))) - (c (ipc/ipc "get-local-files-meta" graph-uuid base-path filepaths))))] (assert (not (instance? ExceptionInfo r)) "get-local-files-meta shouldn't return exception") (->> r js->clj (map (fn [[path metadata]] - (->FileMetadata (get metadata "size") (get metadata "md5") (path-normalize path) - (get metadata "encryptedFname") (get metadata "mtime") false nil))))))) + (let [normalized-path (path-normalize path) + encryptedFname (if (not= path normalized-path) + (first (FileMetadata (get metadata "size") (get metadata "md5") normalized-path + encryptedFname (get metadata "mtime") false nil)))))))) (c (ipc/ipc "rename-local-file" graph-uuid base-path (path-normalize from) @@ -887,7 +894,7 @@ :secretKey secret-key :publicKey public-key})))) - (c (.getLocalAllFilesMeta mobile-util/file-sync (clj->js {:graphUUID graph-uuid :basePath base-path}))))] @@ -896,13 +903,15 @@ (->> (.-result r) js->clj (map (fn [[path metadata]] - (->FileMetadata (get metadata "size") (get metadata "md5") - ;; return decoded path, keep it consistent with RSAPI - (path-normalize path) - (get metadata "encryptedFname") (get metadata "mtime") false nil))) + (let [normalized-path (path-normalize path) + encryptedFname (if (not= path normalized-path) + (first (FileMetadata (get metadata "size") (get metadata "md5") normalized-path + encryptedFname (get metadata "mtime") false nil)))) set))))) - (c (.getLocalFilesMeta mobile-util/file-sync (clj->js {:graphUUID graph-uuid @@ -912,11 +921,12 @@ (->> (.-result r) js->clj (map (fn [[path metadata]] - (->FileMetadata (get metadata "size") (get metadata "md5") - ;; return decoded path, keep it consistent with RSAPI - (path-normalize path) - (get metadata "encryptedFname") (get metadata "mtime") false nil))) - set)))) + (let [normalized-path (path-normalize path) + encryptedFname (if (not= path normalized-path) + (first (FileMetadata (get metadata "size") (get metadata "md5") normalized-path + encryptedFname (get metadata "mtime") false nil)))))))) (c (.renameLocalFile mobile-util/file-sync @@ -1228,7 +1238,7 @@ (mapv #(->FileMetadata (:size %) (:checksum %) - (path-normalize (get encrypted-path->path-map (:encrypted-path %))) + (get encrypted-path->path-map (:encrypted-path %)) (:encrypted-path %) (:last-modified %) true nil)