2024-10-02 19:00:15 +01:00
|
|
|
// Package permcheck contains code for simplifying permissions checks on files
|
|
|
|
// and directories.
|
|
|
|
package permcheck
|
|
|
|
|
|
|
|
import (
|
2024-11-27 16:19:11 +00:00
|
|
|
"context"
|
|
|
|
"log/slog"
|
2024-10-02 19:00:15 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// File type constants for logging.
|
|
|
|
const (
|
|
|
|
typeDir = "directory"
|
|
|
|
typeFile = "file"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Check checks the permissions on important files. It logs the results at
|
|
|
|
// appropriate levels.
|
2024-11-27 16:19:11 +00:00
|
|
|
func Check(
|
|
|
|
ctx context.Context,
|
|
|
|
l *slog.Logger,
|
|
|
|
workDir string,
|
|
|
|
dataDir string,
|
|
|
|
statsDir string,
|
|
|
|
querylogDir string,
|
|
|
|
confFilePath string,
|
|
|
|
) {
|
|
|
|
check(ctx, l, workDir, dataDir, statsDir, querylogDir, confFilePath)
|
2024-10-02 19:00:15 +01:00
|
|
|
}
|
|
|
|
|
2024-11-27 16:19:11 +00:00
|
|
|
// NeedsMigration returns true if AdGuard Home files need permission migration.
|
|
|
|
func NeedsMigration(ctx context.Context, l *slog.Logger, workDir, confFilePath string) (ok bool) {
|
|
|
|
return needsMigration(ctx, l, workDir, confFilePath)
|
2024-10-02 19:00:15 +01:00
|
|
|
}
|
|
|
|
|
2024-11-27 16:19:11 +00:00
|
|
|
// Migrate attempts to change the permissions of AdGuard Home's files. It logs
|
|
|
|
// the results at an appropriate level.
|
|
|
|
func Migrate(
|
|
|
|
ctx context.Context,
|
|
|
|
l *slog.Logger,
|
|
|
|
workDir string,
|
|
|
|
dataDir string,
|
|
|
|
statsDir string,
|
|
|
|
querylogDir string,
|
|
|
|
confFilePath string,
|
|
|
|
) {
|
|
|
|
migrate(ctx, l, workDir, dataDir, statsDir, querylogDir, confFilePath)
|
2024-10-02 19:00:15 +01:00
|
|
|
}
|