ref: 16e1d99c6dd7e2acb362123ee7dea3e221f11177
parent: bf8a61fde5696f56a77473f062bbff58d4b219ca
author: Bjørn Erik Pedersen <[email protected]>
date: Mon Jan 1 09:23:51 EST 2018
resource: Create target dir if not exists This is the case where image processing is triggered from shortcodes, i.e. before the target page's folder in /public is created. Fixes #4202
--- a/resource/image.go
+++ b/resource/image.go
@@ -411,7 +411,19 @@
defer in.Close()
out, err := i.spec.Fs.Destination.Create(target)
- if err != nil {
+ if err != nil && os.IsNotExist(err) {
+ // When called from shortcodes, the target directory may not exist yet.
+ // See https://github.com/gohugoio/hugo/issues/4202
+ if err = i.spec.Fs.Source.MkdirAll(filepath.Dir(target), os.FileMode(0755)); err != nil {
+ res = err
+ return
+ }
+ out, err = i.spec.Fs.Destination.Create(target)
+ if err != nil {
+ res = err
+ return
+ }
+ } else if err != nil {
res = err
return
}