Remove Bom files#10
Open
shmuelko wants to merge 81 commits into
Open
Conversation
stask
requested changes
Jul 12, 2020
| :dependencies [[org.clojure/clojure "1.10.0"] | ||
| [org.flatland/useful "0.9.0"]] | ||
| [org.flatland/useful "0.9.0"] | ||
| ;; [org.clojure/clj-bom "0.1.2"] |
Member
There was a problem hiding this comment.
If you don't need dependency please remove it
Comment on lines
+32
to
+39
| (defn file-bom [file] | ||
| (let [domless-file (debomify (slurp file)) | ||
| full-path (str/split file #"/") | ||
| directory (str/join "/" (butlast full-path)) | ||
| filename (last full-path) | ||
| new-path (str directory "/tmp/" filename)] | ||
| (when (not (.exists (io/file (str directory "/tmp")))) (.mkdir (java.io.File. (str directory "/tmp")))) | ||
| (spit new-path domless-file))) |
Member
There was a problem hiding this comment.
Few issues here:
- did you mean
bomless-filenotdomless-file? - To get a parent directory you should use
getAbsolutePathnot split (different operating systems use different separators) - the temp folder should be passed from outside, you might not have write access to the folder with reports, so you might not be able to create a
tmpfolder there. - you already have
io/filefunction, why do you also need to usejava.io.File.constructor directly? - instead of concatenating strings manually, you can use
(io/file "SOME_FOLDER" "SOME_OTHER_FOLDER" "FILE_NAME"), it's a variadic function and also you have the same issue that separator on windows is different than on linux/mac
Comment on lines
+80
to
+88
| (defn return-file [file] | ||
| (pprint/pprint (slurp file))) | ||
|
|
||
| (defn return-files [directory] | ||
| (let [filtered-files (filter (fn [file] (str/ends-with? (.getAbsolutePath file) ".xml")) (file-seq directory)) | ||
| filtered-paths (for [file filtered-files] (.getAbsolutePath file)) | ||
| files (for [path filtered-paths] (return-file path))] | ||
| files)) | ||
|
|
stask
requested changes
Jul 14, 2020
Comment on lines
+11
to
+17
| (defn delete-recursively [fname] | ||
| (let [func (fn [func f] | ||
| (when (.isDirectory f) | ||
| (doseq [f2 (.listFiles f)] | ||
| (func func f2))) | ||
| (clojure.java.io/delete-file f))] | ||
| (func func (clojure.java.io/file fname)))) |
Member
There was a problem hiding this comment.
You already importing the clojure.java.io namespace, so no need to use fully-qualified name.
Besides, you don't really need to define an additional function here. You can do something like this:
(defn delete-recursively! [fname]
(let [f (io/file fname)]
(when (.isDirectory f)
(doseq [child-path (.listFiles f)]
(delete-recursively! child-path)))
(io/delete-file f)))
Comment on lines
+40
to
+53
| (defn file-bom [path] | ||
| (let [bomless-file (debomify (slurp path)) | ||
| directory (.getParent (io/file path)) | ||
| directory-name (.getName (io/file directory)) | ||
| directory-parent (.getParent (io/file directory)) | ||
| filename (.getName (io/file path)) | ||
| seperator (if (str/includes? path "/") "/" "\\") | ||
| new-path (str directory-parent seperator "tmp" seperator directory-name seperator filename)] | ||
| (when | ||
| (not (.exists (io/file (str directory-parent seperator "tmp")))) | ||
| (.mkdir (io/file (str directory-parent seperator "tmp")))) | ||
| (when (not (.exists (io/file (str directory-parent seperator "tmp" seperator directory-name)))) | ||
| (.mkdir (io/file (str directory-parent seperator "tmp" seperator directory-name)))) | ||
| (spit new-path bomless-file))) |
Member
There was a problem hiding this comment.
Not really sure what you were trying to do here.
Let's go over it again.
- The reports folder might not be writeable. You need to pass a path where we will create temporary files. This will also remove the need for "filtering".
- Do not build paths manually. Use
(io/file "folder" "subfolder" "file name")
Contributor
Author
There was a problem hiding this comment.
now I got this.
will modify the code accordingly
Contributor
Author
There was a problem hiding this comment.
Here I create another folder on the base folder level and then create a folder for each reports-path inside "tmp" folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Will go over files and remove bom character if exists