Skip to content

Commit

Permalink
Assure files are truncated when we don't append to them!
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Aug 19, 2019
1 parent 8d53f0c commit 707a96d
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.5
4.0.6
1 change: 1 addition & 0 deletions lib/tools/src/substitute/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl StreamOrPath {
Box::new(
OpenOptions::new()
.create(true)
.truncate(!append)
.write(true)
.append(append)
.open(p)
Expand Down
5 changes: 5 additions & 0 deletions release.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### V4.0.6: Dependency Update

* Assure writes to a single unique output file will overwrite its complete content during substitution.
* Previously, if you would write less than the original file size, parts of the previous content may still be present.

### V4.0.5: Dependency Update

* upgrade all dependencies to the latest version
Expand Down
29 changes: 27 additions & 2 deletions tests/included-stateless-substitute.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ title "'substitute' subcommand"

(with "stdin for data"
(with "input as yaml"
(with "multiple template from a file to the same output file"
(with "multiple (2) template from a file to the same output file"
(sandbox
(with "the default document separator"
it "succeeds" && {
Expand All @@ -106,7 +106,7 @@ title "'substitute' subcommand"
expect_snapshot "$snapshot/data-stdin-yaml-multi-template-to-same-file-output" output
}
)
(when "writing to the same output file again"
(when "writing to the same output file again (1)"
it "succeeds" && {
echo "the-answer: 42" | \
WITH_SNAPSHOT="$snapshot/data-stdin-yaml-multi-template-to-same-file-again" \
Expand All @@ -130,6 +130,31 @@ title "'substitute' subcommand"
)
)
)
(with "multiple (3) template from a file to the same output file"
(sandbox
(with "the default document separator"
it "succeeds" && {
echo "the-answer: 42" | \
WITH_SNAPSHOT="$snapshot/data-stdin-yaml-multi-template-to-same-file-more" \
expect_run $SUCCESSFULLY "$exe" substitute "$template/the-answer.hbs:output" "$template/the-answer.hbs:output" "$template/the-answer.hbs:output"
}

it "produces the expected output, which is a single document separated by the document separator" && {
expect_snapshot "$snapshot/data-stdin-yaml-multi-template-to-same-file-more-output" output
}
)
(when "writing to the same output file again (2)"
it "succeeds" && {
echo "the-answer: 42" | \
WITH_SNAPSHOT="$snapshot/data-stdin-yaml-multi-template-to-same-file-again-more" \
expect_run $SUCCESSFULLY "$exe" substitute "$template/the-answer.hbs:output" "$template/the-answer.hbs:output"
}
it "overwrites the previous output file entirely" && {
expect_snapshot "$snapshot/data-stdin-yaml-multi-template-to-same-file-again-more-output" output
}
)
)
)
)
)
(with "stdin for templates"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Q>: What is the answer to everything?
<A>: 42

<Q>: What is the answer to everything?
<A>: 42
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
<Q>: What is the answer to everything?
<A>: 42

<Q>: What is the answer to everything?
<A>: 42
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Q>: What is the answer to everything?
<A>: 42

<Q>: What is the answer to everything?
<A>: 42

<Q>: What is the answer to everything?
<A>: 42

0 comments on commit 707a96d

Please sign in to comment.