launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/worker/uniter/tools.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  	"os"
     8  	"path/filepath"
     9  
    10  	"launchpad.net/errgo/errors"
    11  	"launchpad.net/juju-core/worker/uniter/jujuc"
    12  )
    13  
    14  // EnsureJujucSymlinks creates a symbolic link to jujuc within dir for each
    15  // hook command. If the commands already exist, this operation does nothing.
    16  func EnsureJujucSymlinks(dir string) (err error) {
    17  	for _, name := range jujuc.CommandNames() {
    18  		// The link operation fails when the target already exists,
    19  		// so this is a no-op when the command names already
    20  		// exist.
    21  		err := os.Symlink("./jujud", filepath.Join(dir, name))
    22  		if err == nil {
    23  			continue
    24  		}
    25  		// TODO(rog) drop LinkError check when fix is released (see http://codereview.appspot.com/6442080/)
    26  		if e, ok := err.(*os.LinkError); !ok || !os.IsExist(e.Err) {
    27  			return errors.Notef(err, "cannot initialize hook commands in %q", dir)
    28  		}
    29  	}
    30  	return nil
    31  }