gohugoio / hugo

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

cleanDestinationDir in the config file is ignored sometimes #8433

Open Kzer-Za opened 3 years ago

Kzer-Za commented 3 years ago

hugo v0.81.0+extended linux/amd64 BuildDate=unknown

Specifically, it seems to be ignored if you have never used this option from CLI. After installing Hugo I just put cleanDestinationDir: true in config.yaml of the site I'm trying to make. However, the command hugo never deleted any directories or files that were becoming obsolete. For example, I first built the site with the default taxonomies, but later decided that I didn't need them, so I disabled them with

disableKinds:
- taxonomy
- term

However, after running hugo the directories "tags" and "categories" were still in "public". The same was the case with obsolete files/directories in "content". Only after I have commented the option cleanDestinationDir: true in the config.yaml and ran hugo --cleanDestinationDir from the command line did Hugo build the "public" directory without the obsolete files/directories.

After that, to test the issue, I uncommented the line in the config and ran just hugo. But now the option in config is working and the obsolete files are deleted from "public" as they should. It's like something has been initialized by running hugo --cleanDestinationDir once.

matt9189 commented 3 years ago

I am unable to reproduce this error. When I create a new site and run hugo with the default config, it creates the two folders. When I modify the config file with the following: disableKinds = ["taxonomy", "term"] cleanDestinationDir = true It removes the two folders from the public folder as expected.

jmooring commented 3 years ago

I can reproduce the problem.

TLDR --cleanDestinationDir fails to remove items from the public directory unless the static directory is present.

hugo new site mysite
cd mysite
hugo
find . -type d -name categories -o -name tags

The categories and tags directories are present (PASS).

hugo --disableKinds "taxonomy,term" --cleanDestinationDir
find . -type d -name categories -o -name tags

The categories and tags directories are gone (PASS).

hugo
find . -type d -name categories -o -name tags

The categories and tags directories are present (PASS).

rmdir static
hugo --disableKinds "taxonomy,term" --cleanDestinationDir
find . -type d -name categories -o -name tags

The categories and tags directories are still present (FAIL).

mkdir static
hugo --disableKinds "taxonomy,term" --cleanDestinationDir
find . -type d -name categories -o -name tags

The categories and tags directories are gone (PASS).

This may not be the only way to trigger the problem.

bep commented 3 years ago

So, this get skipped if there are no static directories.

I suggest that we in that case just do a "walk and Remove" in the DestionationFs -- but we need to respect the filter that we apply in the normal case:

https://github.com/gohugoio/hugo/blob/3d5dbdcb1a11b059fc2f93ed6fadb9009bf72673/commands/hugo.go#L653

ResamVi commented 3 years ago

With the help of @jmooring's string of commands and with respect to what @bep mentioned I made the pull request that atleast fixes that kind failure we observed right now