cljsjs / boot-cljsjs

Helper tasks to aid the packaging of JS dependencies for Clojurescript projects
66 stars 22 forks source link

Downloaded file cannot be deleted in Windows #43

Open pupeno opened 7 years ago

pupeno commented 7 years ago

It looks like after expanding the downloading zip, it is deleted but that doesn't work on Windows:

C:\Users\pupeno\Documents\Dashman\packages\react-toolbox>boot package target install
Downloading 1.3.3.zip
Extracting 377 files
                              java.lang.Thread.run              Thread.java:  745
java.util.concurrent.ThreadPoolExecutor$Worker.run  ThreadPoolExecutor.java:  617
 java.util.concurrent.ThreadPoolExecutor.runWorker  ThreadPoolExecutor.java: 1142
               java.util.concurrent.FutureTask.run          FutureTask.java:  266
                                               ...
               clojure.core/binding-conveyor-fn/fn                 core.clj: 1916
                                 boot.core/boot/fn                 core.clj: 1029
                               boot.core/run-tasks                 core.clj: 1019
      cljsjs.boot-cljsjs.packaging/eval216/fn/G/fn            packaging.clj:   86
      cljsjs.boot-cljsjs.packaging/eval53/fn/fn/fn            packaging.clj:   25
     cljsjs.boot-cljsjs.packaging/eval104/fn/fn/fn            packaging.clj:   53
                                 boot.core/commit!                 core.clj:  463
                    boot.tmpdir.TmpFileSet/commit!               tmpdir.clj:  254
                             boot.file/delete-file                 file.clj:   71
                                               ...
                       clojure.java.io/delete-file                   io.clj:  426
java.io.IOException: Couldn't delete C:\Users\pupeno\.boot\cache\tmp\Users\pupeno\Documents\Dashman\packages\react-toolbox\5g0\u2qisy\1.3.3.zip
timerooney commented 7 years ago

I am running into a similar issue on Windows while trying to update the vis.js package. It also looks like the sift function before the unzipping is completed. That is a possible explanation for why the zip file cannot be deleted, since it is still being accessed at the time that deletion is requested.

> boot package install target
Downloading v4.20.1.zip
Extracting 564 files
java.io.IOException: Couldn't delete C:\Users\trooney\.boot\cache\tmp\Users\trooney\Dev\fixes\cljsjs\packages\vis\bes\f0sqpx\v4.20.1.zip
     clojure.java.io/delete-file/invokeStatic         io.clj:  434
                  clojure.java.io/delete-file         io.clj:  430
                                          ...
                        boot.file/delete-file       file.clj:   55
               boot.tmpdir.TmpFileSet/commit!     tmpdir.clj:  248
                            boot.core/commit!       core.clj:  451
cljsjs.boot-cljsjs.packaging/eval137/fn/fn/fn  packaging.clj:   53
 cljsjs.boot-cljsjs.packaging/eval86/fn/fn/fn  packaging.clj:   25
 cljsjs.boot-cljsjs.packaging/eval249/fn/G/fn  packaging.clj:   86
                          boot.core/run-tasks       core.clj:  938
                            boot.core/boot/fn       core.clj:  948
          clojure.core/binding-conveyor-fn/fn       core.clj: 1938
                                          ...
Sifting output files...
Sifting output files...
clojure.lang.ExceptionInfo: Assert failed: No .inc.js file found!
                            regular
    data: {:file
           "C:\\Users\\trooney\\AppData\\Local\\Temp\\boot.user9067136962680214853.clj",
           :line 19}
  java.lang.AssertionError: Assert failed: No .inc.js file found!
                            regular
cljsjs.boot-cljsjs.packaging/eval296/fn/fn/fn  packaging.clj:  115
               boot.task.built-in/fn/fn/fn/fn   built_in.clj:  493
               boot.task.built-in/fn/fn/fn/fn   built_in.clj:  493
cljsjs.boot-cljsjs.packaging/eval137/fn/fn/fn  packaging.clj:   40
 cljsjs.boot-cljsjs.packaging/eval86/fn/fn/fn  packaging.clj:   25
 cljsjs.boot-cljsjs.packaging/eval249/fn/G/fn  packaging.clj:   86
                          boot.core/run-tasks       core.clj:  938
                            boot.core/boot/fn       core.clj:  948
          clojure.core/binding-conveyor-fn/fn       core.clj: 1938
                                          ...
timerooney commented 7 years ago

At least in the case of vis.js on Windows, unzip in cljsjs.boot-cljsjs.packaging is not fully unzipping the archive. However, the sequence between BEGIN and END is completed before the deletion is attempted, so my initial guess for the cause of the issue was incorrect.

(c/deftask unzip
  [p paths PATH #{str} "Paths in fileset to unzip"]
  (let [tmp (c/tmp-dir!)]
    (c/with-pre-wrap fileset
      (let [archives (filter (comp paths c/tmp-path) (c/ls fileset))]
        ;;; BEGIN
        (doseq [archive archives
                :let [zipfile (ZipFile. (c/tmp-file archive))
                      entries (->> (.entries zipfile)
                                   enumeration-seq
                                   (remove #(.isDirectory %)))]]
          (util/info "Extracting %d files\n" (count entries))
          (doseq [entry entries
                  :let [target (io/file tmp (.getName entry))]]
            (io/make-parents target)
            (with-open [is (.getInputStream zipfile entry) ]
              (io/copy is target))))
        ;;; END
        (-> fileset (c/rm archives) (c/add-resource tmp) c/commit!)))))
timerooney commented 7 years ago

I can confirm that this issue does not effect Debian 9 using cljsjs.boot-cljsjs 0.5.2 and cljsjs.boot-cljsjs 0.6.0. Presumably, this issue is exclusive to Windows, but I did not thoroughly verify it. Here is my basic system information:

> uname -a
Linux hostname 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u2 (2017-06-26) x86_64 GNU/Linux