Skip to content

Commit

Permalink
Merge pull request #8258 from dolthub/fulghum/dolt-8250
Browse files Browse the repository at this point in the history
Bug fix: Testing for invalid global configuration dir permissions earlier, to prevent a panic
  • Loading branch information
fulghum authored Aug 13, 2024
2 parents 5179caf + b242c13 commit 891ce8b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
9 changes: 5 additions & 4 deletions go/cmd/dolt/dolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,11 @@ func runMain() int {
return 1
}

if dEnv.CfgLoadErr != nil {
cli.PrintErrln(color.RedString("Failed to load the global config. %v", dEnv.CfgLoadErr))
return 1
}

strMetricsDisabled := dEnv.Config.GetStringOrDefault(config.MetricsDisabled, "false")
var metricsEmitter events.Emitter
metricsEmitter = events.NewFileEmitter(homeDir, dbfactory.DoltDir)
Expand All @@ -520,10 +525,6 @@ func runMain() int {

events.SetGlobalCollector(events.NewCollector(doltversion.Version, metricsEmitter))

if dEnv.CfgLoadErr != nil {
cli.PrintErrln(color.RedString("Failed to load the global config. %v", dEnv.CfgLoadErr))
return 1
}
globalConfig, ok := dEnv.Config.GetConfig(env.GlobalConfig)
if !ok {
cli.PrintErrln(color.RedString("Failed to get global config"))
Expand Down
43 changes: 43 additions & 0 deletions integration-tests/bats/no-repo.bats
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,46 @@ NOT_VALID_REPO_ERROR="The current directory is not a valid dolt repository."
[ "$status" -eq 1 ]
[[ "$output" =~ "Unknown Command notarealcommand" ]] || false
}

@test "no-repo: the global dolt directory is not accessible due to permissions" {
noPermissionsDir=$(mktemp -d -t noPermissions-XXXX)
chmod 000 $noPermissionsDir
DOLT_ROOT_PATH=$noPermissionsDir

run dolt version
[ "$status" -eq 1 ]
[[ "$output" =~ "Failed to load the global config" ]] || false
[[ "$output" =~ "permission denied" ]] || false

run dolt sql
[ "$status" -eq 1 ]
[[ "$output" =~ "Failed to load the global config" ]] || false
[[ "$output" =~ "permission denied" ]] || false

run dolt sql-server
[ "$status" -eq 1 ]
[[ "$output" =~ "Failed to load the global config" ]] || false
[[ "$output" =~ "permission denied" ]] || false
}

@test "no-repo: the global dolt directory is accessible, but not writable" {
noPermissionsDir=$(mktemp -d -t noPermissions-XXXX)
chmod 000 $noPermissionsDir
chmod a+x $noPermissionsDir
DOLT_ROOT_PATH=$noPermissionsDir

run dolt version
[ "$status" -eq 1 ]
[[ "$output" =~ "Failed to load the global config" ]] || false
[[ "$output" =~ "permission denied" ]] || false

run dolt sql
[ "$status" -eq 1 ]
[[ "$output" =~ "Failed to load the global config" ]] || false
[[ "$output" =~ "permission denied" ]] || false

run dolt sql-server
[ "$status" -eq 1 ]
[[ "$output" =~ "Failed to load the global config" ]] || false
[[ "$output" =~ "permission denied" ]] || false
}

0 comments on commit 891ce8b

Please sign in to comment.