diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-04-07 10:13:55 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-04-07 10:13:55 +0200 |
commit | d8d6a25b5755bedaf90261a1539dc37a2f05c3df (patch) | |
tree | 0a67b319135be289355a6b84c785f4fe976da7c9 | |
parent | 9f12be54ee84f24efdf7c58f05867e8d0dea2ccb (diff) |
modules: Fix hugo mod vendor for regular file mounts
Fixes #7140
-rw-r--r-- | modules/client.go | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/modules/client.go b/modules/client.go index a82300b37..8ee9f588a 100644 --- a/modules/client.go +++ b/modules/client.go @@ -194,6 +194,9 @@ func (c *Client) Vendor() error { if err := c.rmVendorDir(vendorDir); err != nil { return err } + if err := c.fs.MkdirAll(vendorDir, 0755); err != nil { + return err + } // Write the modules list to modules.txt. // @@ -228,8 +231,27 @@ func (c *Client) Vendor() error { dir := t.Dir() for _, mount := range t.Mounts() { - if err := hugio.CopyDir(c.fs, filepath.Join(dir, mount.Source), filepath.Join(vendorDir, t.Path(), mount.Source), nil); err != nil { - return errors.Wrap(err, "failed to copy module to vendor dir") + sourceFilename := filepath.Join(dir, mount.Source) + targetFilename := filepath.Join(vendorDir, t.Path(), mount.Source) + fi, err := c.fs.Stat(sourceFilename) + if err != nil { + return errors.Wrap(err, "failed to vendor module") + } + + if fi.IsDir() { + if err := hugio.CopyDir(c.fs, sourceFilename, targetFilename, nil); err != nil { + return errors.Wrap(err, "failed to copy module to vendor dir") + } + } else { + targetDir := filepath.Dir(targetFilename) + + if err := c.fs.MkdirAll(targetDir, 0755); err != nil { + return errors.Wrap(err, "failed to make target dir") + } + + if err := hugio.CopyFile(c.fs, sourceFilename, targetFilename); err != nil { + return errors.Wrap(err, "failed to copy module file to vendor") + } } } |