1
0
mirror of https://github.com/lxc/distrobuilder.git synced 2026-02-05 15:46:17 +01:00
Files
distrobuilder/generators/utils.go
Thomas Hipp d85172810c *: Switch to errors without stack traces
The zap logger includes the verbose output if the error implements the
Formatter interface which errors.Error (from the pkg/errors package)
does. This includes the stack trace which causes the visible error
message to be rather messy.

Using fmt.Errorf and errors.New (standard library) solves the problem
as these don't implement the Formatter interface.

Signed-off-by: Thomas Hipp <thomas.hipp@canonical.com>
2021-09-03 11:05:03 +02:00

53 lines
1.0 KiB
Go

package generators
import (
"fmt"
"os"
"strconv"
"github.com/lxc/distrobuilder/shared"
)
func updateFileAccess(file *os.File, defFile shared.DefinitionFile) error {
// Change file mode if needed
if defFile.Mode != "" {
mode, err := strconv.ParseUint(defFile.Mode, 8, 64)
if err != nil {
return fmt.Errorf("Failed to parse file mode: %w", err)
}
err = file.Chmod(os.FileMode(mode))
if err != nil {
return fmt.Errorf("Failed to change file mode: %w", err)
}
}
// Change gid if needed
if defFile.GID != "" {
gid, err := strconv.Atoi(defFile.GID)
if err != nil {
return fmt.Errorf("Failed to parse GID: %w", err)
}
err = file.Chown(-1, gid)
if err != nil {
return fmt.Errorf("Failed to change GID: %w", err)
}
}
// Change uid if needed
if defFile.UID != "" {
uid, err := strconv.Atoi(defFile.UID)
if err != nil {
return fmt.Errorf("Failed to parse UID: %w", err)
}
err = file.Chown(uid, -1)
if err != nil {
return fmt.Errorf("Failed to change UID: %w", err)
}
}
return nil
}