config: fix parsing of file permissions
These reintroduces the braindead '744' syntax for file permissions. Even though this number isn't octal, it is assumed by convention to be. In order to pull this off, coerceNodes() was introduced to try to counteract the type inferrencing that occurs during the yaml unmarshalling. The config is unmarshalled twice: once into an empty interface and once into the CloudConfig structure. The two resulting node structures are combined together. The nodes from the CloudConfig process replace those from the interface{} when the types of the two nodes are compatible. For example, with the input `0744`, yaml interprets that as the integer 484 giving us the nodes '0744'(string) and 484(int). Because the types string and int are compatible, we opt to take the string node instead of the integer.
This commit is contained in:
@@ -43,7 +43,7 @@ func (f *File) Permissions() (os.FileMode, error) {
|
||||
}
|
||||
|
||||
// Parse string representation of file mode as integer
|
||||
perm, err := strconv.ParseInt(f.RawFilePermissions, 0, 32)
|
||||
perm, err := strconv.ParseInt(f.RawFilePermissions, 8, 32)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("Unable to parse file permissions %q as integer", f.RawFilePermissions)
|
||||
}
|
||||
|
@@ -97,7 +97,7 @@ func TestDecimalFilePermissions(t *testing.T) {
|
||||
|
||||
wf := File{config.File{
|
||||
Path: fn,
|
||||
RawFilePermissions: "484", // Decimal representation of 0744
|
||||
RawFilePermissions: "744",
|
||||
}}
|
||||
|
||||
path, err := WriteFile(&wf, dir)
|
||||
|
Reference in New Issue
Block a user