Comments (5)
Thanks! I'm sure you're right. The weird thing is, this works as expected on MacOS. I don't know enough about the respective kernels to know why this would be, but adding O_TRUNC
to the flags doesn't change the behaviour at all. If it fixes your problem on Windows, I see no reason not to make this change. I'll run up a PR for it.
from script.
Hi John,
I confirm that the fix works for me (Linux Arch, go 1.17.5, 'fix_truncate_bug_81' branch).
Many thanks for the fix.
Cheers,
Lyderic
from script.
I don't think that it's a Windows only problem. I am on Linux (ubuntu LTS 20.04, kernel 5.11, go 1.17.1) and I have the same behaviour as the OP.
Example program to reproduce:
package main
import (
"github.com/bitfield/script"
)
func main() {
script.Echo("abcdef").WriteFile("foo")
script.Echo("bar").WriteFile("foo")
script.File("foo").Stdout()
}
The output of the program is 'bardef', whereas I would expect the output to be 'bar'.
Many thanks for looking into this and also many thanks for the script library!
from script.
It must be working accidentally because I've only been able to test it on macOS, then! Thanks for the report @lyderic.
from script.
This isn't a macOS issue, just me being dumb. The test for WriteFile
didn't actually test that it truncates the file, only that it successfully creates a new one. I added a TestWriteFileTruncatesExisting
, which writes a bunch of zeroes to the file, and then calls WriteFile
with slightly fewer bytes. If there are still zeroes left at the end of the file, then the truncating hasn't worked.
This fails as expected on my macOS system, so I've added the O_TRUNC
flag as suggested. This passes the test for me.
@lyderic and @badrelmers, would you mind testing my candidate fix in 1c76e65? If it passes tests and runs your example programs correctly, then we're all good. Many thanks for the report.
from script.
Related Issues (20)
- gitignore entry for Intellij IDEA HOT 4
- Feature Request: Add FilterFunc HOT 2
- Basename introduces a line feed HOT 1
- How can I check the progress of a script.Exec() command? HOT 2
- Interaction with bubbletea HOT 10
- Propose adding a delimeter to Column()
- Add Base64 encode and decode methods HOT 6
- Suggestion: `./go-script -c 'script.Stdin()...'` tool for running these HOT 5
- Should `ExecForEach` sanitize or escape arguments differently? HOT 9
- Parameterize a script.Pipe with a user data struct ? HOT 5
- Execv function HOT 1
- how to get the stdout of the Exec result? HOT 3
- Race condition in Pipe.Exec HOT 4
- Methods for mkdir and touch HOT 2
- Conditinally execute statements. HOT 2
- How to create folder, delete folder and list folder contents ? HOT 4
- Feature Suggestion: Fields HOT 4
- Makefile replacement HOT 2
- Expand prompt logic for PR #199
- Easy Utility Functions to Create Symbolic/Hard Links HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from script.