~rogpeppe/juju-core/azure

« back to all changes in this revision

Viewing changes to utils/file.go

  • Committer: William Reade
  • Date: 2012-01-20 21:32:53 UTC
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: fwereade@gmail.com-20120120213253-csks5e12opl8t1rq
hefty rearrangement, few actual changes

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
 
}