Skip to content

Commit

Permalink
Allow a 'tmp' directory during dolt init
Browse files Browse the repository at this point in the history
  • Loading branch information
macneale4 committed Dec 17, 2024
1 parent 6d9d278 commit c172912
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 4 additions & 3 deletions go/cmd/dolt/system_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"os"
"path/filepath"

"github.com/dolthub/dolt/go/libraries/doltcore/env"
"github.com/dolthub/dolt/go/libraries/utils/file"
"github.com/dolthub/dolt/go/libraries/utils/filesys"
"github.com/dolthub/dolt/go/store/util/tempfiles"
Expand Down Expand Up @@ -47,7 +48,7 @@ func reconfigIfTempFileMoveFails(dataDir filesys.Filesys) error {
dotDoltCreated = true
}

doltTmpDir := filepath.Join(doltDir, "tmp")
doltTmpDir := filepath.Join(doltDir, env.TmpDirName)
stat, err = os.Stat(doltTmpDir)
if err != nil {
err := os.MkdirAll(doltTmpDir, os.ModePerm)
Expand Down Expand Up @@ -76,7 +77,7 @@ func reconfigIfTempFileMoveFails(dataDir filesys.Filesys) error {

err = file.Rename(name, movedName)
if err == nil {
// tmp file system is the same as the data dir, so no need to change it.
// If rename was successful, then the tmp dir is fine, so no need to change it. Clean up the things we created.
_ = file.Remove(movedName)

if tmpDirCreated {
Expand All @@ -89,7 +90,7 @@ func reconfigIfTempFileMoveFails(dataDir filesys.Filesys) error {

return nil
}
_ = file.Remove(movedName)
_ = file.Remove(name)

// Rename failed. So we force the tmp dir to be the data dir.
tempfiles.MovableTempFileProvider = tempfiles.NewTempFileProviderAt(doltTmpDir)
Expand Down
14 changes: 12 additions & 2 deletions go/libraries/doltcore/env/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const (
DefaultRemotesApiPort = "443"

tempTablesDir = "temptf"

TmpDirName = "tmp"
)

var zeroHashStr = (hash.Hash{}).String()
Expand Down Expand Up @@ -450,13 +452,21 @@ func (dEnv *DoltEnv) createDirectories(dir string) (string, error) {
}

if dEnv.hasDoltDir(dir) {
// Special case a completely empty directory. We can allow that.
// Special case a completely empty directory, or one which has a "tmp" directory but nothing else.
// The `.dolt/tmp` directory is created while verifying that we can rename table files which is early
// in the startup process. It will only exist if we need it because the TMPDIR environment variable is set to
// a path which is on a different partition than the .dolt directory.
dotDolt := mustAbs(dEnv, dbfactory.DoltDir)
entries, err := os.ReadDir(dotDolt)
if err != nil {
return "", err
}
if len(entries) != 0 {

if len(entries) == 1 {
if !entries[0].IsDir() || entries[0].Name() != TmpDirName {
return "", fmt.Errorf(".dolt directory already exists at '%s'", dir)
}
} else if len(entries) != 0 {
return "", fmt.Errorf(".dolt directory already exists at '%s'", dir)
}
}
Expand Down

0 comments on commit c172912

Please sign in to comment.