gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.78k stars 7.53k forks source link

readDir broken in 0.93.2 when directories are symlinks/Linux AR>M64 #9609

Closed gj52 closed 2 years ago

gj52 commented 2 years ago

What version of Hugo are you using (hugo version)?

$ hugo version 0.93.2
works with 0.93.1 !

Does this issue reproduce with the latest release?

YES


Dev on Windows is fine. Prod on Linux breaks, can not find file or directory

path is assets/etc/apache2 with some copied conf files from /etc should find apache2.conf

index.md

+++
date        = "2018-11-12T11:50:21+01:00"
description = "Konfiguration Apache2"
title       = "Apache2"
draft       = false
chapter     = 1002
+++

## Apache
{{< linux/shortlist path="apache2" type="conf" >}}

### conf-enabled
{{< linux/shortlist path="apache2/conf-enabled" type="conf">}}

### mods-enabled
{{< linux/shortlist path="apache2/mods-enabled" type="conf">}}

### sites-enabled
{{< linux/shortlist path="apache2/sites-enabled" type="conf">}}

## Let's Encrypt Apache 
{{< linux/shortlist path="letsencrypt/" type="conf">}}

shortcode is

{{ $path     := .Get "path" }}
{{ $filepath := printf "/assets/etc/%s" $path }}
{{ $files    := readDir $filepath }}
{{ $ext := default "-" (.Get "type" )}}
{{ if (fileExists $filepath)}}
<div class="pa2 mh4 ba">
{{- range $files }}
    {{ if (and (ne (substr .Name 0 1) "_") (not .IsDir)) }}{{ $f := resources.Get (printf "etc/%s/%s" $path .Name)}}
        {{ $e := findRE "\\w+$" .Name }}
        {{ if (or ( eq $ext "-") (in $e $ext) )}}
            <a class="w-auto pr2" href={{$f.Permalink }} type=text/plain rel=nofollow download>{{ .Name }}</a>
        {{end}}
    {{end}}
{{- end }}
</div>
{{end}}
bep commented 2 years ago

@gj52 these files, do they live below the theme directory?

gj52 commented 2 years ago

The shortcode is in the theme directory. Theme extract is here. The listed files are in //etc/

If you need to look in my complete activ repo, send me a PM.

bep commented 2 years ago

@gj52 what I need is something that ... fails, does the "theme extract" fail for you?

gj52 commented 2 years ago

Sample does not fail ... mmh I have an idea about - copied some lines

assets/etc is a symbolic link to /etc - I want to dokument my production server all used files have attribute R for everyone, so the user generating the websites can read it all

hugo@pi4:~/spielwiese $ cd assets
hugo@pi4:~/spielwiese/assets $ cd etc
hugo@pi4:~/spielwiese/assets/etc $ cd apache2/
hugo@pi4:~/spielwiese/assets/etc/apache2 $ cd conf-enabled/
hugo@pi4:~/spielwiese/assets/etc/apache2/conf-enabled $ ll
total 0
lrwxrwxrwx 1 root root 30 Feb  4 13:42 charset.conf -> ../conf-available/charset.conf
lrwxrwxrwx 1 root root 28 Feb  4 13:57 hints.conf -> ../conf-available/hints.conf
lrwxrwxrwx 1 root root 44 Feb  4 13:42 localized-error-pages.conf -> ../conf-available/localized-error-pages.conf
lrwxrwxrwx 1 root root 46 Feb  4 13:42 other-vhosts-access-log.conf -> ../conf-available/other-vhosts-access-log.conf
lrwxrwxrwx 1 root root 31 Feb  4 13:42 security.conf -> ../conf-available/security.conf

hugo@pi4:~/spielwiese/assets/etc/apache2/conf-enabled $ cat charset.conf
# Read the documentation before enabling AddDefaultCharset.
# In general, it is only a good idea if you know that all your files
# have this encoding. It will override any encoding given in the files
# in meta http-equiv or xml encoding tags.

#AddDefaultCharset UTF-8

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
hugo@pi4:~/spielwiese/assets/etc/apache2/conf-enabled $

## ERROR message:

Error: Error building site: "/home/hugo/spielwiese/content/intern/1002_Apache2/index.md:13:1": failed to render shortcode "linux/shortlist": failed to process shortcode: "/home/hugo/spielwiese/themes/photon/layouts/shortcodes/linux/shortlist.html:3:16": execute of template failed: template: shortcodes/linux/shortlist.html:3:16: executing "shortcodes/linux/shortlist.html" at <readDir $filepath>: error calling readDir: failed to read directory "/assets/etc/apache2/conf-enabled": decorate: lstat /assets: no such file or directory

maybe the links don't work here

HTH

bep commented 2 years ago

OK, now I actually understand what's happening. Thanks for the detailed explanation.

bep commented 2 years ago

OK, I have tried, but I'm not able to reproduce this error. I assume the issue is related to symlinks, but the devil is in the detail, I'm afraid.

gj52 commented 2 years ago

OK,

can depend from the specific OS-runtime

I'm on Linux pi4 5.10.92-v8+ #1514 SMP PREEMPT ... aarch64 GNU/Linux

Ask, if you need more information.

gj52 commented 2 years ago

Version 0.93.3 works! Thanks

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.