Skip to content

Conversation

@shmuelko
Copy link
Contributor

Will go over files and remove bom character if exists

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"]
Copy link
Member

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

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)))
Copy link
Member

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-file not domless-file?
  • To get a parent directory you should use getAbsolutePath not 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 tmp folder there.
  • you already have io/file function, why do you also need to use java.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))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this for?

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))))
Copy link
Member

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)))

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)))
Copy link
Member

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")

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants