Issac Trotts for the GopherCon 2019 Liveblog on July 25, 2019
Presenter: Oliver Stenbom
Liveblogger: Issac Trotts
When the core of a language fails you, and you can't remove a file, how can you fix it? Oliver will share his contribution journey from bug to merge in a crucial part of Golang: the os package. Discover how Golang manages platform independence and how even novices can contribute Unix system calls.
Lots hidden between the lines, like what can I offer to Go, what can it contribute to me, and the contribution experience.
At one point, long file paths with many nested directories could not be removed with os.RemoveAll
. Such long names are created by accident or malicious intent.
Our first attempt at solving this was to shell out to rm -rf
, but it wasn't such a great solution. In addition to not working on Windows, it didn't tell us
anything about what caused the problem.
The real cause was that Open
, Stat
, and Remove
were all failing with long filenames.
Using Openat
, Statat
, and Removeat
solves this problem.
Their signature looks like for example Removeat(directory, path)
where directory
is a file descriptor.
Just replace Stat()
/Remove()
with *at()
versions.
We did this in own code base and it solved our problem, but we wanted to help the Go community so we decided to contribute our fix to the Go standard library.
We created an issue, with a snippet of code reproducing the problem etc.
Main hurdles:
RemoveAll
was simple, platform independent*at
sys call version is unix specific.Use the more general solution if you can, make it more specific if you have to
Stat
, Open
, Remove
are all system calls under the hood.A system call is
*at
not on Go on all systemsIan Taylor said to implement the basic version, then let the community help you with the rest. Trying to do it all at once makes it less likely for your contribution to succeed.
Long and meandering path to getting the solution merged. Problem, solution, development, discussion, improvement, merge, revert, merge.
the os package
Original rm -rf
: 46 additions
Local solution without shelling out: 226 additions.
Solution contributed to Go standard library: over 600 additions.