dot
dot

Reputation: 627

Copy contents of symlink to directory

I am trying to copy the contents of a symlink directory to a normal directory on Windows:

file { "copy symlink contents to directory":
    ensure             => directory,
    path               => "C:/Users/devacct/Desktop/puppet/puppet_dir2/", #directory
    source             => "C:/Users/devacct/Desktop/puppet/filessym/", #symlink
    recurse            => true,
    source_permissions => ignore,
    links              => 'manage',
    #ignore             => $ignore_files,
    #purge              => $purge,
    force              => true,
}

This fails with an error message:

Error: /Stage[main]/Custom::Profile::Symlink/File[copy symlink contents to directory]: Could not evaluate: Could not retrieve information from environment production source(s) file:/C:/Users/devacct/Desktop/puppet/filessym

Is it valid to give symlink path as a value to source attribute? If not, how do I achieve my objective?

Upvotes: 0

Views: 550

Answers (2)

Alex Harvey
Alex Harvey

Reputation: 15472

Yes, it is valid in general to use a symlink as the source parameter, and as noted by Kelson Silva, you would also need to use links => follow instead of links => manage (see docs).

I am not sure why you are getting that error message though.

FWIW, I tested the following on Mac OS X:

Set up:

$ ls -ld /tmp/symlink
lrwxr-xr-x  1 alexharvey  wheel  10 12 May 16:31 /tmp/symlink@ -> realsource
$ ls -lL /tmp/symlink
total 0
drwxr-xr-x  5 alexharvey  wheel  160 12 May 16:30 a/
drwxr-xr-x  5 alexharvey  wheel  160 12 May 16:30 b/
drwxr-xr-x  5 alexharvey  wheel  160 12 May 16:30 c/
$ find /tmp/symlink/
/tmp/symlink/
/tmp/symlink//a
/tmp/symlink//a/f
/tmp/symlink//a/d
/tmp/symlink//a/d/somefile
/tmp/symlink//a/e
/tmp/symlink//c
/tmp/symlink//c/f
/tmp/symlink//c/d
/tmp/symlink//c/e
/tmp/symlink//b
/tmp/symlink//b/f
/tmp/symlink//b/d
/tmp/symlink//b/e

Code:

file { '/tmp/dest':
  ensure             => directory,
  links              => follow,
  source             => '/tmp/symlink',
  recurse            => true,
  source_permissions => ignore,
  force              => true,
}

Result:

Notice: Compiled catalog for harveya-c02vj38lhtd7-ume.local in environment production in 0.03 seconds
Notice: /Stage[main]/Test/File[/tmp/dest]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/a]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/a/d]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/a/d/somefile]/ensure: defined content as '{md5}d41d8cd98f00b204e9800998ecf8427e'
Notice: /Stage[main]/Test/File[/tmp/dest/a/e]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/a/f]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/b]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/b/d]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/b/e]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/b/f]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/c]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/c/d]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/c/e]/ensure: created
Notice: /Stage[main]/Test/File[/tmp/dest/c/f]/ensure: created
Notice: Applied catalog in 0.13 seconds

Upvotes: 0

Kelson Silva
Kelson Silva

Reputation: 532

Use the link attribute on your file block with follow.

Also, set the source without the last backslash... Give this a try.

file { "copy symlink contents to directory":
    ensure             => directory,
    path               => "C:/Users/devacct/Desktop/puppet/puppet_dir2/", #directory
    source             => "C:/Users/devacct/Desktop/puppet/filessym", #symlink
    recurse            => true,
    source_permissions => ignore,
    links              => 'follow',
    #ignore             => $ignore_files,
    #purge              => $purge,
    force              => true,
}

Upvotes: 1

Related Questions