Jira (PUP-6914) ruby expand_path in file type breaks leading-tilde file resources

2 views
Skip to first unread message

Christopher Wood (JIRA)

unread,
Nov 10, 2016, 5:45:03 PM11/10/16
to puppe...@googlegroups.com
Christopher Wood created an issue
 
Puppet / Bug PUP-6914
ruby expand_path in file type breaks leading-tilde file resources
Issue Type: Bug Bug
Affects Versions: PUP 4.8.0
Assignee: Unassigned
Components: Types and Providers
Created: 2016/11/10 2:44 PM
Environment:

$ uname -a
Linux cwl 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) x86_64 GNU/Linux
$ cat /etc/debian_version
8.6
$ puppet --version
4.8.0
$ /opt/puppetlabs/puppet/bin/ruby --version
ruby 2.1.9p490 (2016-03-30 revision 54437) [x86_64-linux]

Priority: Minor Minor
Reporter: Christopher Wood

This to reproduce:

$ cat x.pp 
file { '/tmp/x~x':
  content => "x\n",
}
 
file { '/tmp/~x':
  content => "x\n",
}
 
file { '/tmp/x~':
  content => "x\n",
}
$ puppet apply /tmp/x.pp 
Notice: Compiled catalog for cwl.hostopia.com in environment production in 0.07 seconds
Error: Could not set 'file' on ensure: user x20161110-10084-1ubfm2v doesn't exist at /tmp/x.pp:5
Error: Could not set 'file' on ensure: user x20161110-10084-1ubfm2v doesn't exist at /tmp/x.pp:5
Wrapped exception:
user x20161110-10084-1ubfm2v doesn't exist
Error: /Stage[main]/Main/File[/tmp/~x]/ensure: change from absent to file failed: Could not set 'file' on ensure: user x20161110-10084-1ubfm2v doesn't exist at /tmp/x.pp:5
Notice: Applied catalog in 0.12 seconds

I can't by any stretch call myself a programmer, but it turns out people on stackoverflow are having related behaviour (huzzah googling for "ruby tilde filename", no quotes).

http://stackoverflow.com/questions/2504646/how-to-open-files-relative-to-home-directory

From the ruby docs, expand_path says that a ~user filename expands to that user's home directory. It doesn't seem to be quite what's going on here but it's still bringing in the username.

https://ruby-doc.org/core-2.1.8/File.html#method-c-expand_path

Sure enough, the file type uses expand_path to sort out where the :path is.

https://github.com/puppetlabs/puppet/blob/master/lib/puppet/type/file.rb

The bug part appears to be where the file type is implicitly presuming that the file path is not literal from the file resource, if I'm reading this right. (Not a programmer.)

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe)
Atlassian logo

Christopher Wood (JIRA)

unread,
Nov 10, 2016, 6:13:23 PM11/10/16
to puppe...@googlegroups.com

Josh Cooper (JIRA)

unread,
Nov 11, 2016, 1:13:14 PM11/11/16
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-6914

Puppet has historically collapsed multiple leading slashes in the file type, which is why we're using File.expand_path. In 2.7.20, we regressed on that see https://github.com/puppetlabs/puppet/commit/912ed3468b0a20ac66454c1c2b2984fc692ebe70. We fixed the regression in https://github.com/puppetlabs/puppet/commit/35bf229 (see https://projects.puppetlabs.com/issues/19727). However, File.expand_path goes too far by expanding tilde. We maybe able to use Pathname.cleanpath, or collapse leading slashes ourselves.

Josh Cooper (JIRA)

unread,
Nov 11, 2016, 1:14:04 PM11/11/16
to puppe...@googlegroups.com
Josh Cooper updated an issue
 
Change By: Josh Cooper
Team: Agent & Platform
Sprint: AP Triage

Geoff Nichols (JIRA)

unread,
Nov 17, 2016, 1:48:03 PM11/17/16
to puppe...@googlegroups.com

Geoff Nichols (JIRA)

unread,
Dec 20, 2016, 8:10:10 PM12/20/16
to puppe...@googlegroups.com

Geoff Nichols (JIRA)

unread,
Dec 21, 2016, 11:36:08 PM12/21/16
to puppe...@googlegroups.com

Geoff Nichols (JIRA)

unread,
Jan 3, 2017, 8:35:09 PM1/3/17
to puppe...@googlegroups.com

Geoff Nichols (JIRA)

unread,
Jan 5, 2017, 12:34:06 AM1/5/17
to puppe...@googlegroups.com

Geoff Nichols (JIRA)

unread,
Apr 5, 2017, 1:07:07 AM4/5/17
to puppe...@googlegroups.com

Maggie Dreyer (JIRA)

unread,
May 16, 2017, 4:46:03 PM5/16/17
to puppe...@googlegroups.com

Josh Cooper (JIRA)

unread,
May 22, 2017, 12:42:03 AM5/22/17
to puppe...@googlegroups.com

Guillaume (JIRA)

unread,
May 30, 2017, 4:13:04 AM5/30/17
to puppe...@googlegroups.com
Guillaume commented on Bug PUP-6914
 
Re: ruby expand_path in file type breaks leading-tilde file resources

Bump on this issue, I'm hitting the same problem with filenames starting with a tilde (~). These files come from an external provider and we can't rename them. Any chance for a workaround or a fix ?

Josh Cooper (Jira)

unread,
Dec 1, 2021, 11:17:03 PM12/1/21
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-6914

This was fixed in PUP-5800.

$ cat x.pp 
file { '/tmp/x~x':
  content => "x\n",
}
 
file { '/tmp/~x':
  content => "x\n",
}
 
file { '/tmp/x~':
  content => "x\n",
}
 
$ bx puppet apply x.pp
Notice: Compiled catalog for localhost in environment production in 0.01 seconds
Notice: /Stage[main]/Main/File[/tmp/x~x]/ensure: defined content as '{sha256}73cb3858a687a8494ca3323053016282f3dad39d42cf62ca4e79dda2aac7d9ac'
Notice: /Stage[main]/Main/File[/tmp/~x]/ensure: defined content as '{sha256}73cb3858a687a8494ca3323053016282f3dad39d42cf62ca4e79dda2aac7d9ac'
Notice: /Stage[main]/Main/File[/tmp/x~]/ensure: defined content as '{sha256}73cb3858a687a8494ca3323053016282f3dad39d42cf62ca4e79dda2aac7d9ac'
Notice: Applied catalog in 0.05 seconds
 
$ ls -l /tmp/x~x /tmp/~x /tmp/x~
-rw-r--r-- 1 josh 2 Dec  1 20:15 /tmp/~x
-rw-r--r-- 1 josh 2 Dec  1 20:15 /tmp/x~
-rw-r--r-- 1 josh 2 Dec  1 20:15 /tmp/x~x

 

This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages