Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(511)

Side by Side Diff: go/src/infra/tools/cipd/local/rename_windows.go

Issue 1258673004: cipd: Make it work on Windows. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // +build windows
6
7 package local
8
9 import (
10 "syscall"
11 "unsafe"
12 )
13
14 // See https://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85 ).aspx
15
16 var (
17 kernel32 = syscall.NewLazyDLL("kernel32.dll")
18 procMoveFileExW = kernel32.NewProc("MoveFileExW")
19 )
20
21 const (
22 moveFileReplaceExisting = 1
23 moveFileWriteThrough = 8
24 )
25
26 func moveFileEx(source, target *uint16, flags uint32) error {
27 ret, _, err := procMoveFileExW.Call(uintptr(unsafe.Pointer(source)), uin tptr(unsafe.Pointer(target)), uintptr(flags))
28 if ret == 0 {
29 if err != nil {
30 return err
31 }
32 return syscall.EINVAL
33 }
34 return nil
35 }
36
37 func atomicRename(source, target string) error {
38 lpReplacedFileName, err := syscall.UTF16PtrFromString(target)
39 if err != nil {
40 return err
41 }
42 lpReplacementFileName, err := syscall.UTF16PtrFromString(source)
43 if err != nil {
44 return err
45 }
46 return moveFileEx(lpReplacementFileName, lpReplacedFileName, moveFileRep laceExisting|moveFileWriteThrough)
47 }
OLDNEW
« go/src/infra/tools/cipd/local/fs.go ('K') | « go/src/infra/tools/cipd/local/rename_posix.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698