Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restore: support for symlinks (experimental) (#621)
- Loading branch information
Showing
9 changed files
with
143 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// +build linux darwin | ||
|
||
package restore | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func symlinkChtimes(ctx context.Context, linkPath string, atime, mtime time.Time) error { | ||
return unix.Lutimes(linkPath, []unix.Timeval{ | ||
unix.NsecToTimeval(atime.UnixNano()), | ||
unix.NsecToTimeval(mtime.UnixNano()), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package restore | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
"golang.org/x/sys/windows" | ||
) | ||
|
||
func symlinkChtimes(ctx context.Context, linkPath string, atime, mtime time.Time) error { | ||
fta := windows.NsecToFiletime(atime.UnixNano()) | ||
ftw := windows.NsecToFiletime(mtime.UnixNano()) | ||
|
||
fn, err := windows.UTF16PtrFromString(linkPath) | ||
if err != nil { | ||
return errors.Wrap(err, "UTF16PtrFromString") | ||
} | ||
|
||
h, err := windows.CreateFile( | ||
fn, windows.GENERIC_READ|windows.GENERIC_WRITE, | ||
windows.FILE_SHARE_READ|windows.FILE_SHARE_WRITE, | ||
nil, windows.OPEN_EXISTING, | ||
windows.FILE_FLAG_OPEN_REPARSE_POINT, 0) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer windows.CloseHandle(h) //nolint:errcheck | ||
|
||
return windows.SetFileTime(h, &ftw, &fta, &ftw) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters