github.com/cloudbase/juju-core@v0.0.0-20140504232958-a7271ac7912f/worker/uniter/tools_linux.go (about)

     1  // Copyright 2012, 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package uniter
     5  
     6  import (
     7  	"fmt"
     8  	"os"
     9  	"path/filepath"
    10  
    11  	"launchpad.net/juju-core/worker/uniter/jujuc"
    12      "launchpad.net/juju-core/utils"
    13  )
    14  
    15  // EnsureJujucSymlinks creates a symbolic link to jujuc within dir for each
    16  // hook command. If the commands already exist, this operation does nothing.
    17  
    18  // TODO: gsamfira: port EnsureJujucSymlinks to Windows. Need to setup a folder
    19  // in %PATH% for all juju commands
    20  // TODO: gsamfira: Create symlink function for windows using syscall
    21  func EnsureJujucSymlinks(dir string) (err error) {
    22  	for _, name := range jujuc.CommandNames() {
    23  		// The link operation fails when the target already exists,
    24  		// so this is a no-op when the command names already
    25  		// exist.
    26  		err := utils.Symlink("./jujud", filepath.Join(dir, name))
    27  		if err == nil {
    28  			continue
    29  		}
    30  		// TODO(rog) drop LinkError check when fix is released (see http://codereview.appspot.com/6442080/)
    31  		if e, ok := err.(*os.LinkError); !ok || !os.IsExist(e.Err) {
    32  			return fmt.Errorf("cannot initialize hook commands in %q: %v", dir, err)
    33  		}
    34  	}
    35  	return nil
    36  }