0

Context:

A ubuntu Virtualbox VM having shared folders from a Windows host. Provisioner: chef-solo

Assuming there is a path /tmp/shared_data and I am attempting to created a symlink on it like

ln -s /var/www /tmp/shared_data/web_root

It fails saying protocol error

Begin output of "bash" "/tmp/chef-script20161020-6826-kore5t" ----

==> dev:     STDOUT:
==> dev:     STDERR: ln: failed to create symbolic link ‘/tmp/shared_data/web_root’: Protocol error
==> dev:     ---- End output of "bash"  "/tmp/chef-script20161020-6826-kore5t" ----
==> dev:     Ran "bash"  "/tmp/chef-script20161020-6826-kore5t" returned 1

I would imagine this is because since the path I am attempting to make a symlink on is the windows FS and does not support it.

So is there a way I can detect if symlink can be created in a path before hand before I attempt it and thus breaking my build.

1

You could parse the output of mount and decide what the filesystem type is for that path. That would be the most portable, but cumbersome (since that only gives direct information for the mountpoints, not the subdirectories). However some system-specific approaches are given in

You are probably looking to ensure that this is not a cifs filesystem. For instance, you could do something like this:

if df -t cifs /tmp/shared_data/web_root 2>/dev/null
then
    echo cannot make a symbolic link...
else
    ln -s /var/www /tmp/shared_data/web_root
fi 

The manual page for Ubuntu's df says of -t:

-t, --type=TYPE
limit listing to file systems of type TYPE

which differs from POSIX df:

-t
[XSI] Include total allocated-space figures in the output.

So you can have simple or portable.

  • Awesome will try this later. – Starx Oct 21 '16 at 8:56
  • In my case it is returning df: no file systems processed – Starx Oct 22 '16 at 15:32
  • You probably overlooked the redirection of stderr to /dev/null, i.e., "2>/dev/null". Given that, I do not see the error message, and the exit code from df is 1 (meaning an error). – Thomas Dickey Oct 22 '16 at 19:02
  • I am not sure, but instead of giving the message it tried to create the symlink again, so I ran that terminal without the redirection and that is what I got. – Starx Oct 23 '16 at 7:25
  • To make your build work properly, you have to do something (such as copying files) so that the attempt to create a symbolic link is satisfied. There's not enough detail in the question to see whether copying the directory would be a good idea, so I left it with just a message. – Thomas Dickey Oct 23 '16 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.