Jira (PUP-11334) tidy removes non-empty directories

14 views
Skip to first unread message

Stefan Möding

unread,
Nov 8, 2021, 12:40:03 PM11/8/21
to puppe...@googlegroups.com
Stefan Möding created an issue
 
Puppet / Bug PUP-11334
tidy removes non-empty directories
Issue Type: Bug Bug
Affects Versions: PUP 7.12.0, PUP 6.25.0
Assignee: Unassigned
Components: Types and Providers
Created: 2021/11/08 9:38 AM
Priority: Normal Normal
Reporter: Stefan Möding

Puppet Version: 6.25.0 & 7.12.0
Puppet Server Version: 7.4.1
OS Name/Version: Debian-10 Buster

The type documentation for tidy has the following description for the rmdirs parameter: Tidy directories in addition to files; that is, remove directories whose age is older than the specified criteria. This will only remove empty directories, so all contained files must also be tidied before a directory gets removed.

It seems that directories are removed when in fact they are not empty (which removes files that should not be removed). Also the value mtime for the parameter type seems to be important to trigger the issue.

Use the following manifest tidy.pp:

tidy { '/tmp/tidy':
 age     => '1m',
 rmdirs  => true,
 recurse => true,
 type    => 'mtime',
}

 Run the following shell script:

#!/bin/sh -x
mkdir /tmp/tidy
touch /tmp/tidy/file1
sleep 70
touch /tmp/tidy/file2
puppet apply --verbose tidy.pp

 The script creates a directory and a file in it. The it waits 70 seconds to ensure the file modification time is more that one minute ago. It creates anothe file and runs the manifest. Puppet should remove files/directories where the modification time is more than 1 minute ago.

Desired Behavior:

Since /tmp/tidy/file2 is less than one minute old, it should still exist after Puppet is done.

Actual Behavior:

The directory /tmp/tidy including the file /tmp/tidy/file2 is removed by Puppet.

The output of the script:

+ mkdir /tmp/tidy
+ touch /tmp/tidy/file1
+ sleep 70
+ touch /tmp/tidy/file2
+ puppet apply --verbose tidy.pp
Notice: Compiled catalog for puppet.example.com in environment production in 0.04 seconds
Info: Using environment 'production'
Notice: /Stage[main]/Main/Tidy[/tmp/tidy]: Tidying 1 files
Info: Applying configuration version '1636391335'
Notice: /Stage[main]/Main/File[/tmp/tidy/file1]/ensure: removed
Notice: Applied catalog in 0.02 seconds

 The removal of /tmp/tidy is clearly shown in the log. 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

Josh Cooper (Jira)

unread,
Nov 10, 2021, 3:29:02 PM11/10/21
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Epic Link: PUP-7547

Josh Cooper (Jira)

unread,
Nov 10, 2021, 3:29:03 PM11/10/21
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-11334
 
Re: tidy removes non-empty directories

I can confirm this is a bug with a slightly different reproduction:

# cat <<END > tidy.pp
tidy { '/tmp/tidy':
 age     => '1h',
 rmdirs  => true,
 recurse => true,
 type    => 'mtime',
}
END
# cat <<END > script.sh 
#!/bin/sh -x
mkdir -p /tmp/tidy
touch /tmp/tidy/file1
touch -d "-5 hours" /tmp/tidy/file2
# the following simulates the directory's mtime being updated when file2 is created above
touch -d "-5 hours" /tmp/tidy
puppet apply --verbose tidy.pp
END
# chmod u+x script.sh
# ./script.sh
...
Info: Loading facts
Notice: Compiled catalog for XXX in environment production in 0.02 seconds
Info: Using environment 'production'
Notice: /Stage[main]/Main/Tidy[/tmp/tidy]: Tidying 2 files
Info: Applying configuration version '1636573435'
Notice: /Stage[main]/Main/File[/tmp/tidy/file2]/ensure: removed
Notice: /Stage[main]/Main/File[/tmp/tidy]/ensure: removed
Notice: Applied catalog in 0.01 seconds

The problem is that when determining if a directory should be tidied or not, we don't check to see if all of its children will be tidied. And since we set force=>true then we rm -rf the directory.

Ciprian Badescu (Jira)

unread,
Nov 17, 2021, 3:25:02 AM11/17/21
to puppe...@googlegroups.com
Ciprian Badescu updated an issue
Change By: Ciprian Badescu
Team: Night's Watch

Ciprian Badescu (Jira)

unread,
Nov 17, 2021, 3:25:03 AM11/17/21
to puppe...@googlegroups.com
Ciprian Badescu updated an issue
Change By: Ciprian Badescu
Sprint: NW - 2021-12-06

Ciprian Badescu (Jira)

unread,
Nov 17, 2021, 3:55:03 AM11/17/21
to puppe...@googlegroups.com
Ciprian Badescu updated an issue
Change By: Ciprian Badescu
Story Points: 3

Ciprian Badescu (Jira)

unread,
Nov 17, 2021, 4:13:01 AM11/17/21
to puppe...@googlegroups.com
Ciprian Badescu updated an issue
Change By: Ciprian Badescu
Sprint: NW - 2021-12-06

Ciprian Badescu (Jira)

unread,
Nov 17, 2021, 4:13:02 AM11/17/21
to puppe...@googlegroups.com
Ciprian Badescu updated an issue
Change By: Ciprian Badescu
Story Points: 3

Ciprian Badescu (Jira)

unread,
Nov 17, 2021, 4:13:02 AM11/17/21
to puppe...@googlegroups.com
Ciprian Badescu updated an issue
Change By: Ciprian Badescu
Team: Night's Watch Coremunity

Ciprian Badescu (Jira)

unread,
Dec 6, 2021, 10:27:01 AM12/6/21
to puppe...@googlegroups.com
Ciprian Badescu updated an issue
Change By: Ciprian Badescu
Sprint: NW - 2022-01-12

Ciprian Badescu (Jira)

unread,
Jan 4, 2022, 4:13:02 AM1/4/22
to puppe...@googlegroups.com
Ciprian Badescu updated an issue
 
Puppet / Bug PUP-11334
tidy removes non-empty directories
Change By: Ciprian Badescu
Sprint: NW - 2022-01-12
Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.20.2#820002-sha1:829506d)
Atlassian logo

Ciprian Badescu (Jira)

unread,
Jan 10, 2022, 10:59:01 AM1/10/22
to puppe...@googlegroups.com
Ciprian Badescu updated an issue
Change By: Ciprian Badescu
Team: Coremunity Phoenix
Reply all
Reply to author
Forward
0 new messages