~rogpeppe/juju-core/azure

« back to all changes in this revision

Viewing changes to utils/file.go

  • Committer: Gustavo Niemeyer
  • Date: 2011-09-26 14:48:45 UTC
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: gustavo@niemeyer.net-20110926144845-atwp3u6blqngmhel
Bootstrapping store package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2013 Canonical Ltd.
2
 
// Licensed under the AGPLv3, see LICENCE file for details.
3
 
 
4
 
package utils
5
 
 
6
 
import (
7
 
        "os"
8
 
        "path/filepath"
9
 
        "strings"
10
 
)
11
 
 
12
 
// NormalizePath replaces a leading ~ with $HOME, and removes any .. or . path
13
 
// elements.
14
 
func NormalizePath(dir string) string {
15
 
        if strings.HasPrefix(dir, "~/") {
16
 
                dir = filepath.Join(os.Getenv("HOME"), dir[2:])
17
 
        }
18
 
        return filepath.Clean(dir)
19
 
}