Update to newest pkglib
This commit is contained in:
parent
1bdcb6e3b4
commit
7ff2ecf7fe
11 changed files with 95 additions and 41 deletions
|
|
@ -45,8 +45,12 @@ func (pcfg PathsConfig) UsingDistilleryExecutable() bool {
|
|||
// When it does not exist, falls back to the default executable.
|
||||
func (pcfg PathsConfig) CurrentExecutable() string {
|
||||
exe, err := os.Executable()
|
||||
if err != nil || !fsx.IsRegular(exe) {
|
||||
return pcfg.ExecutablePath()
|
||||
if err == nil {
|
||||
isFile, err := fsx.IsRegular(exe, true)
|
||||
if err == nil && isFile {
|
||||
return exe
|
||||
}
|
||||
}
|
||||
return exe
|
||||
|
||||
return pcfg.ExecutablePath()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,11 @@ func ValidateFile(path *string, dflt string) error {
|
|||
if *path == "" {
|
||||
*path = dflt
|
||||
}
|
||||
if !fsx.IsRegular(*path) {
|
||||
isFile, err := fsx.IsRegular(*path, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !isFile {
|
||||
return errors.Errorf("%q does not exist or is not a file", *path)
|
||||
}
|
||||
return nil
|
||||
|
|
@ -19,7 +23,11 @@ func ValidateDirectory(path *string, dflt string) error {
|
|||
if *path == "" {
|
||||
*path = dflt
|
||||
}
|
||||
if !fsx.IsDirectory(*path) {
|
||||
isDirectory, err := fsx.IsDirectory(*path, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !isDirectory {
|
||||
return errors.Errorf("%q does not exist or is not a directory", *path)
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -51,12 +51,17 @@ func (dis *Exporter) ArchivePath() string {
|
|||
// NewArchivePath returns the path to a new archive with the provided prefix.
|
||||
// The path is guaranteed to not exist.
|
||||
func (dis *Exporter) NewArchivePath(prefix string) (path string) {
|
||||
// TODO: Consider moving these into a subdirectory with the provided prefix.
|
||||
for path == "" || fsx.Exists(path) {
|
||||
for {
|
||||
name := dis.newSnapshotName(prefix) + ".tar.gz"
|
||||
path = filepath.Join(dis.ArchivePath(), name)
|
||||
|
||||
// Only return if the path does not exist
|
||||
// FIXME: ignoring the error here
|
||||
exists, _ := fsx.Exists(path)
|
||||
if !exists {
|
||||
return path
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// newSnapshot name returns a new basename for a snapshot with the provided prefix.
|
||||
|
|
|
|||
|
|
@ -42,9 +42,15 @@ func (pv *Provision) Provision(progress io.Writer, ctx context.Context, flags Pr
|
|||
}
|
||||
|
||||
// check that the base directory does not exist
|
||||
logging.LogMessage(progress, "Checking that base directory %s does not exist", instance.FilesystemBase)
|
||||
if fsx.IsDirectory(instance.FilesystemBase) {
|
||||
return nil, ErrInstanceAlreadyExists
|
||||
{
|
||||
logging.LogMessage(progress, "Checking that base directory %s does not exist", instance.FilesystemBase)
|
||||
exists, err := fsx.Exists(instance.FilesystemBase)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if exists {
|
||||
return nil, ErrInstanceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
// Store in the instances table!
|
||||
|
|
|
|||
|
|
@ -35,7 +35,9 @@ var (
|
|||
// NoPrefix checks if this WissKI instance is excluded from generating prefixes.
|
||||
// TODO: Move this to the database!
|
||||
func (prefixes *Prefixes) NoPrefix() bool {
|
||||
return fsx.IsRegular(filepath.Join(prefixes.FilesystemBase, "prefixes.skip"))
|
||||
// FIXME: Ignoring error here!
|
||||
exists, _ := fsx.IsRegular(filepath.Join(prefixes.FilesystemBase, "prefixes.skip"), false)
|
||||
return exists
|
||||
}
|
||||
|
||||
//go:embed prefixes.php
|
||||
|
|
@ -121,16 +123,26 @@ func hasAnyPrefix(candidate string, prefixes []string) bool {
|
|||
|
||||
func (wisski *Prefixes) filePrefixes() (prefixes []string, err error) {
|
||||
path := filepath.Join(wisski.FilesystemBase, "prefixes")
|
||||
if !fsx.IsRegular(path) {
|
||||
return nil, nil
|
||||
|
||||
// check that the prefixes path exists
|
||||
{
|
||||
isFile, err := fsx.IsRegular(path, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !isFile {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
// open the file
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// scan each line
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue