-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e78ac60
commit 4baf8b2
Showing
6 changed files
with
97 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2014 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
// +build !windows | ||
|
||
package wrench | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
func isOwnedByJujuUser(fi os.FileInfo) bool { | ||
statStruct, ok := fi.Sys().(*syscall.Stat_t) | ||
if !ok { | ||
// Uid check is not supported on this platform so assume | ||
// the owner is ok. | ||
return true | ||
} | ||
return int(statStruct.Uid) == jujuUid | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2014 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
// +build !windows | ||
|
||
package wrench_test | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
|
||
gc "launchpad.net/gocheck" | ||
|
||
"github.com/juju/juju/wrench" | ||
) | ||
|
||
const fileNotFound = `stat .+: no such file or directory` | ||
|
||
// Patch out the os.Stat call used by wrench so that a particular file | ||
// appears to be owned by a UID that isn't Juju's UID. | ||
func (s *wrenchSuite) tweakOwner(c *gc.C, targetPath string) { | ||
s.PatchValue(wrench.Stat, func(path string) (fi os.FileInfo, err error) { | ||
fi, err = os.Stat(path) | ||
if err != nil { | ||
return | ||
} | ||
if path == targetPath { | ||
statStruct, ok := fi.Sys().(*syscall.Stat_t) | ||
if !ok { | ||
c.Skip("this test only supports POSIX systems") | ||
} | ||
statStruct.Uid = notJujuUid | ||
} | ||
return | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2014 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package wrench | ||
|
||
import "os" | ||
|
||
// Windows is not fully POSIX compliant | ||
// there is no syscall.Stat_t on Windows | ||
func isOwnedByJujuUser(fi os.FileInfo) bool { | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2014 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package wrench_test | ||
|
||
import ( | ||
gc "launchpad.net/gocheck" | ||
) | ||
|
||
const fileNotFound = "GetFileAttributesEx.*: The system cannot find the (file|path) specified." | ||
|
||
// Patch out the os.Stat call used by wrench so that a particular file | ||
// appears to be owned by a UID that isn't Juju's UID. | ||
func (s *wrenchSuite) tweakOwner(c *gc.C, targetPath string) { | ||
c.Skip("this test only supports POSIX systems") | ||
} |