Symlink on windows

This commit is contained in:
Alex Dadgar
2016-08-31 21:38:04 -07:00
parent 0b07ef93c1
commit 0c050bd62b
3 changed files with 21 additions and 6 deletions

View File

@@ -7,11 +7,17 @@ import (
)
var (
//Path inside container for mounted directory that is shared across tasks in a task group.
// SharedAllocContainerPath is the path inside container for mounted
// directory shared across tasks in a task group.
SharedAllocContainerPath = filepath.Join("c:\\", SharedAllocName)
//Path inside container for mounted directory for local storage.
// TaskLocalContainer is the path inside a container for mounted directory
// for local storage.
TaskLocalContainerPath = filepath.Join("c:\\", TaskLocal)
// TaskSecretsContainerPath is the path inside a container for mounted
// secrets directory
TaskSecretsContainerPath = filepath.Join("c:\\", TaskSecrets)
)
func (d *AllocDir) linkOrCopy(src, dst string, perm os.FileMode) error {
@@ -21,11 +27,16 @@ func (d *AllocDir) linkOrCopy(src, dst string, perm os.FileMode) error {
// Hardlinks the shared directory. As a side-effect the src and dest directory
// must be on the same filesystem.
func (d *AllocDir) mount(src, dest string) error {
return syscall.Link(src, dest)
return os.Symlink(src, dest)
}
func (d *AllocDir) unmount(dir string) error {
return syscall.Unlink(dir)
p, err := syscall.UTF16PtrFromString(dir)
if err != nil {
return err
}
return syscall.RemoveDirectory(p)
}
// The windows version does nothing currently.

View File

@@ -438,6 +438,9 @@ func (c *Client) GetAllocFS(allocID string) (allocdir.AllocDirFS, error) {
if !ok {
return nil, fmt.Errorf("alloc not found")
}
if ar.ctx == nil {
return nil, fmt.Errorf("alloc dir not found")
}
return ar.ctx.AllocDir, nil
}

View File

@@ -156,8 +156,9 @@ func TestClient_ReserveSecretDir(t *testing.T) {
tsd := secretdir.NewTestSecretDir(t)
c.secretDir = tsd
expected := 10
tsd.MemoryUsed = expected
secretUsage := 10
expected := c.Node().Reserved.MemoryMB + secretUsage
tsd.MemoryUsed = secretUsage
c.reserveResources()
res := c.Node().Reserved