From 0c050bd62badb10bb4b787fe0109a56e89076ab1 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Wed, 31 Aug 2016 21:38:04 -0700 Subject: [PATCH] Symlink on windows --- client/allocdir/alloc_dir_windows.go | 19 +++++++++++++++---- client/client.go | 3 +++ client/client_test.go | 5 +++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/client/allocdir/alloc_dir_windows.go b/client/allocdir/alloc_dir_windows.go index a26496b38..951a30789 100644 --- a/client/allocdir/alloc_dir_windows.go +++ b/client/allocdir/alloc_dir_windows.go @@ -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. diff --git a/client/client.go b/client/client.go index 95f405b73..e63d7b4aa 100644 --- a/client/client.go +++ b/client/client.go @@ -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 } diff --git a/client/client_test.go b/client/client_test.go index 0326b5ce3..c5cc3d38b 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -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