schema: change PopulateSymlinkMap to be Map.SetSymlinkTarget

Change-Id: I072ce65331048b54c90c32e951f5034060c1764c
This commit is contained in:
Brad Fitzpatrick 2012-08-22 04:38:25 +10:00
parent a8629ec5dd
commit 228c0ca56f
2 changed files with 6 additions and 8 deletions

View File

@ -325,10 +325,12 @@ func (up *Uploader) uploadNode(n *node) (*client.PutResult, error) {
m := schema.NewCommonFileMap(n.fullPath, fi)
switch {
case mode&os.ModeSymlink != 0:
// TODO(bradfitz): use VFS here; PopulateSymlinkMap uses os.Readlink directly.
if err := schema.PopulateSymlinkMap(m, n.fullPath); err != nil {
// TODO(bradfitz): use VFS here; not os.Readlink
target, err := os.Readlink(n.fullPath)
if err != nil {
return nil, err
}
m.SetSymlinkTarget(target)
case mode&os.ModeDevice != 0:
// including mode & os.ModeCharDevice
fallthrough

View File

@ -525,18 +525,14 @@ func PopulateParts(m Map, size int64, parts []BytesPart) error {
return nil
}
func PopulateSymlinkMap(m Map, fileName string) error {
// SetSymlinkTarget sets m to be of type "symlink" and sets the symlink's target.
func (m Map) SetSymlinkTarget(target string) {
m["camliType"] = "symlink"
target, err := os.Readlink(fileName)
if err != nil {
return err
}
if utf8.ValidString(target) {
m["symlinkTarget"] = target
} else {
m["symlinkTargetBytes"] = []uint8(target)
}
return nil
}
func newBytes() Map {