Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(79)

Issue 14502058: Cross platform Replace function

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 9 months ago by natefinch
Modified:
11 years, 9 months ago
Reviewers:
mp+190461, rog
Visibility:
Public.

Description

Cross platform Replace function Turns out that os.rename works as atomic file replacement on linux, but not on Windows. There's actually no way (as far as I can tell) to atomically replace a file with another one on windows using the go code as written. Luckily, it's not hard to wrap the Windows API in go code and use that.... so that's what this code code. This fixes problems where we try to replace existing files with new ones, which fails on windows (notably during bootstrap). https://code.launchpad.net/~natefinch/juju-core/fix-win-bootstrap/+merge/190461 (do not edit description out of merge proposal)

Patch Set 1 #

Total comments: 1

Patch Set 2 : Cross platform Replace function #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+80 lines, -6 lines) Patch
A [revision details] View 1 1 chunk +2 lines, -0 lines 0 comments Download
M charm/repo.go View 2 chunks +2 lines, -1 line 0 comments Download
M environs/configstore/disk.go View 1 chunk +1 line, -1 line 0 comments Download
M environs/filestorage/filestorage.go View 1 chunk +1 line, -1 line 0 comments Download
A utils/file_unix.go View 1 chunk +14 lines, -0 lines 1 comment Download
A utils/file_windows.go View 1 1 chunk +32 lines, -0 lines 1 comment Download
M utils/fslock/fslock.go View 2 chunks +2 lines, -2 lines 0 comments Download
M utils/trivial.go View 1 chunk +1 line, -1 line 0 comments Download
A utils/zfile_windows.go View 1 chunk +25 lines, -0 lines 0 comments Download

Messages

Total messages: 4
natefinch
Please take a look.
11 years, 9 months ago (2013-10-10 19:57:16 UTC) #1
natefinch
Please take a look.
11 years, 9 months ago (2013-10-10 20:34:46 UTC) #2
rog
LGTM modulo the below; and I think it should be called utils.ReplaceFile, as discussed online. ...
11 years, 9 months ago (2013-10-10 20:38:56 UTC) #3
natefinch
11 years, 9 months ago (2013-10-10 20:59:43 UTC) #4
On 2013/10/10 20:38:56, rog wrote:
> LGTM modulo the below; and I think it should be called utils.ReplaceFile, as
> discussed online.

Yep, done.

> https://codereview.appspot.com/14502058/diff/1/utils/file_windows.go
> File utils/file_windows.go (right):
> 
> https://codereview.appspot.com/14502058/diff/1/utils/file_windows.go#newcode11
> utils/file_windows.go:11: movefile_replace_existing = 0x1
> moveFileReplaceExisting ?

The underscored version is straight out of Microsoft's documentation (except
they capitalize it), so I'm trying to keep it as close to that as possible,
while not exposing them to the outside world.  this is also what syscall does
(though they do expose many of the values).
 
> https://codereview.appspot.com/14502058/diff/4001/utils/file_unix.go
> File utils/file_unix.go (right):
> 
> https://codereview.appspot.com/14502058/diff/4001/utils/file_unix.go#newcode11
> utils/file_unix.go:11: // Replace atomically replaces the destination file or
> directory with the source.
> Perhaps document that the error return is exactly that of os.Rename?

Done.

> https://codereview.appspot.com/14502058/diff/4001/utils/file_windows.go
> File utils/file_windows.go (right):
> 
>
https://codereview.appspot.com/14502058/diff/4001/utils/file_windows.go#newco...
> utils/file_windows.go:18: // Replace atomically replaces the destination file
or
> directory with the source.
> ditto

done.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b