From 50e3217211b519ff53b1c4d55a030fa71bcf1797 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Tue, 27 Sep 2016 11:43:27 -0700 Subject: [PATCH] Avoiding copying files if they are already present in chrootw (#1753) --- client/allocdir/alloc_dir_unix.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/allocdir/alloc_dir_unix.go b/client/allocdir/alloc_dir_unix.go index 0807505c4..0c8185dfc 100644 --- a/client/allocdir/alloc_dir_unix.go +++ b/client/allocdir/alloc_dir_unix.go @@ -28,6 +28,12 @@ var ( ) func (d *AllocDir) linkOrCopy(src, dst string, perm os.FileMode) error { + // Avoid link/copy if the file already exists in the chroot + // TODO 0.6 clean this up. This was needed because chroot creation fails + // when a process restarts. + if fileInfo, _ := os.Stat(dst); fileInfo != nil { + return nil + } // Attempt to hardlink. if err := os.Link(src, dst); err == nil { return nil