use a symlink instead of a copy

Upstream-commit: f9901ead069671c04a2f99c83c1e4d8a13597e7b
Component: engine
This commit is contained in:
Victor Vieux
2013-11-01 13:55:19 -07:00
parent 5e4f415366
commit 771aa307b1
+9 -13
View File
@@ -582,7 +582,7 @@ func NewRuntimeFromDirectory(config *DaemonConfig) (*Runtime, error) {
return nil, err
}
if err := copyLxcStart(config.Root); err != nil {
if err := linkLxcStart(config.Root); err != nil {
return nil, err
}
g, err := NewGraph(path.Join(config.Root, "graph"))
@@ -647,25 +647,21 @@ func (runtime *Runtime) Close() error {
return runtime.containerGraph.Close()
}
func copyLxcStart(root string) error {
func linkLxcStart(root string) error {
sourcePath, err := exec.LookPath("lxc-start")
if err != nil {
return err
}
targetPath := path.Join(root, "lxc-start-unconfined")
sourceFile, err := os.Open(sourcePath)
if err != nil {
if _, err := os.Stat(targetPath); err != nil && !os.IsNotExist(err) {
return err
} else if err == nil {
if err := os.Remove(targetPath); err != nil {
return err
}
}
defer sourceFile.Close()
targetFile, err := os.Create(targetPath)
if err != nil {
return err
}
defer targetFile.Close()
os.Chmod(targetPath, 0755)
_, err = io.Copy(targetFile, sourceFile)
return err
return os.Symlink(sourcePath, targetPath)
}
// History is a convenience type for storing a list of containers,