-
Notifications
You must be signed in to change notification settings - Fork 0
Remove Bom files #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Remove Bom files #10
Conversation
project.clj
Outdated
| :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"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't need dependency please remove it
src/test_xml_parser/core.clj
Outdated
| (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))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
| (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)) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for?
src/test_xml_parser/core.clj
Outdated
| (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)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)))
src/test_xml_parser/core.clj
Outdated
| (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))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now I got this.
will modify the code accordingly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I create another folder on the base folder level and then create a folder for each reports-path inside "tmp" folder
Will go over files and remove bom character if exists