Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGES_FLYBOT.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ still under Backports.
upstream commit it came from. *(partial)* means only some hunks of that commit
were taken.

# Changes to ClojureCLR in Version 1.11.0-flybot4 (unreleased)

## Fixes

* [#32](https://github.com/flybot-sg/clojure-clr/pull/32) `file-mode` opens a
plain write with `FileMode/Create` and `:append` with `FileMode/Append`
instead of `FileMode/OpenOrCreate` for every write, so `spit` and `writer`
truncate the file they overwrite and `:append` appends, like JVM Clojure,
instead of writing at position 0 and dropping the option

# Changes to ClojureCLR in Version 1.11.0-flybot3

## Fixes
Expand Down
7 changes: 4 additions & 3 deletions Clojure/Clojure.Source/clojure/clr/io.clj
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@

(defn- ^FileMode file-mode [mode opts]
(or (:file-mode opts)
(if (= mode :read)
FileMode/Open
FileMode/OpenOrCreate)))
(cond
(= mode :read) FileMode/Open
(:append opts) FileMode/Append
:else FileMode/Create)))

(defn- ^FileShare file-share [opts]
(or (:file-share opts) FileShare/None))
Expand Down
22 changes: 22 additions & 0 deletions Clojure/Clojure.Tests/clojure/test_clojure/clr/io.clj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@
(platform-newlines "WARNING: (slurp f enc) is deprecated, use (slurp f :encoding enc).\n")
(with-out-str
(is (= content (slurp f utf16))))))))))

(deftest test-spit-truncates
(with-temp-file [f]
(spit f "DATA-PRESENT")
(spit f "AB")
(is (= "AB" (slurp f))))
(with-temp-file [f]
(spit f "DATA-PRESENT")
(spit f nil)
(is (= "" (slurp f)))))

(deftest test-spit-append
(with-temp-file [f]
(spit f "AAA")
(spit f "BBB" :append true)
(is (= "AAABBB" (slurp f)))))

(deftest test-spit-file-mode-overrides
(with-temp-file [f]
(spit f "AAA")
(spit f "BBB" :file-mode FileMode/Append)
(is (= "AAABBB" (slurp f)))))

(deftest test-streams-defaults
(let [f (temp-file "test-reader-writer")
Expand Down
Loading