shithub: hugo

Download patch

ref: d8d6a25b5755bedaf90261a1539dc37a2f05c3df
parent: 9f12be54ee84f24efdf7c58f05867e8d0dea2ccb
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Tue Apr 7 06:13:55 EDT 2020

modules: Fix hugo mod vendor for regular file mounts

Fixes #7140

--- a/modules/client.go
+++ b/modules/client.go
@@ -194,6 +194,9 @@
 	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 @@
 		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")
+				}
 			}
 		}