Update to newest pkglib

This commit is contained in:
Tom Wiesing 2023-04-09 22:00:24 +02:00
parent 1bdcb6e3b4
commit 7ff2ecf7fe
No known key found for this signature in database
11 changed files with 95 additions and 41 deletions

View file

@ -120,7 +120,11 @@ func (bs cBootstrap) Run(context wisski_distillery.Context) error {
}
{
if !fsx.IsRegular(cfgPath) {
isFile, err := fsx.IsRegular(cfgPath, false)
if err != nil {
return errBootstrapWriteConfig.Wrap(err)
}
if !isFile {
// generate the configuration from the template
cfg := tpl.Generate()

View file

@ -28,7 +28,11 @@ func (monday) Description() wisski_distillery.Description {
}
func (monday monday) AfterParse() error {
if !fsx.IsRegular(monday.Positionals.GraphdbZip) {
isFile, err := fsx.IsRegular(monday.Positionals.GraphdbZip, false)
if err != nil {
return err
}
if !isFile {
return errNoGraphDBZip.WithMessageF(monday.Positionals.GraphdbZip)
}
return nil

View file

@ -59,9 +59,15 @@ func (r reserve) Run(context wisski_distillery.Context) (err error) {
}
// check that the base directory does not exist
logging.LogMessage(context.Stderr, "Checking that base directory %s does not exist", instance.FilesystemBase)
if fsx.IsDirectory(instance.FilesystemBase) {
return errReserveAlreadyExists.WithMessageF(slug)
{
logging.LogMessage(context.Stderr, "Checking that base directory %s does not exist", instance.FilesystemBase)
exists, err := fsx.Exists(instance.FilesystemBase)
if err != nil {
return errProvisionGeneric.Wrap(err)
}
if exists {
return errReserveAlreadyExists.WithMessageF(slug)
}
}
// setup docker stack

View file

@ -46,8 +46,12 @@ var errNoGraphDBZip = exit.Error{
}
func (s systemupdate) AfterParse() error {
// TODO: Use a generic environment here!
if !fsx.IsRegular(s.Positionals.GraphdbZip) {
isFile, err := fsx.IsRegular(s.Positionals.GraphdbZip, true)
if err != nil {
return err
}
if !isFile {
return errNoGraphDBZip.WithMessageF(s.Positionals.GraphdbZip)
}
return nil

14
go.mod
View file

@ -16,13 +16,13 @@ require (
github.com/pquerna/otp v1.4.0
github.com/rs/zerolog v1.29.0
github.com/tkw1536/goprogram v0.3.5
github.com/tkw1536/pkglib v0.0.0-20230408192227-70bc76c31830
github.com/tkw1536/pkglib v0.0.0-20230409110642-5f57240e294b
github.com/yuin/goldmark v1.5.4
github.com/yuin/goldmark-meta v1.1.0
golang.org/x/crypto v0.7.0
golang.org/x/exp v0.0.0-20230307190834-24139beb5833
golang.org/x/crypto v0.8.0
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
golang.org/x/sync v0.1.0
golang.org/x/term v0.6.0
golang.org/x/term v0.7.0
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.4.7
gorm.io/gorm v1.24.6
@ -48,7 +48,7 @@ require (
github.com/jinzhu/now v1.1.5 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-shellwords v1.0.12 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/term v0.0.0-20221128092401-c43b287e0e0f // indirect
@ -63,8 +63,8 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/tools v0.7.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect

27
go.sum
View file

@ -75,8 +75,8 @@ github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxec
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
@ -115,8 +115,8 @@ github.com/tdewolff/parse v2.3.4+incompatible/go.mod h1:8oBwCsVmUkgHO8M5iCzSIDtp
github.com/tdewolff/test v1.0.7 h1:8Vs0142DmPFW/bQeHRP3MV19m1gvndjUb1sn8yy74LM=
github.com/tkw1536/goprogram v0.3.5 h1:S0axKo3R/vGa4zhYqYDKAZEPhAfwUSSeMtVwnAu4sNY=
github.com/tkw1536/goprogram v0.3.5/go.mod h1:pYr4dMHOSVurbPQ4KTR0ett8XWNISbsRS6zlh9Nsxa8=
github.com/tkw1536/pkglib v0.0.0-20230408192227-70bc76c31830 h1:UQYSSMzlyjfrHaphvEKiI+BTahu5lx//eQwbQFd6ZaM=
github.com/tkw1536/pkglib v0.0.0-20230408192227-70bc76c31830/go.mod h1:RjPEyRcq+g1GMd3D/o7d9WCtVNXY4QZyFRs9hLlZbew=
github.com/tkw1536/pkglib v0.0.0-20230409110642-5f57240e294b h1:qeoY+XHCDx1fubOJkLuMSdz4xNWtgeLpxPfxBiEIj4c=
github.com/tkw1536/pkglib v0.0.0-20230409110642-5f57240e294b/go.mod h1:0A1B9Cc5+yJXR3eeB14CqD4dFSbEjjWRo5Pr9M3XYuI=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
@ -134,10 +134,10 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/exp v0.0.0-20230307190834-24139beb5833 h1:SChBja7BCQewoTAU7IgvucQKMIXrEpFxNMs0spT3/5s=
golang.org/x/exp v0.0.0-20230307190834-24139beb5833/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug=
golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
@ -148,8 +148,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -168,13 +168,14 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ=
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

View file

@ -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()
}

View file

@ -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

View file

@ -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.

View file

@ -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!

View file

@ -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())