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.

Starx
  • 187
  • 1
  • 9

1 Answers1

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.

Thomas Dickey
  • 75,040
  • 9
  • 171
  • 268
  • Awesome will try this later. – Starx Oct 21 '16 at 08: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 07: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
  • WHat kind of details would be helpful? – Starx Oct 23 '16 at 11:35
  • If it's only a few files, I would suggest just copying the webpage. If it's large, I don't have a good suggestion :-) – Thomas Dickey Oct 23 '16 at 14:01
  • Real scenario is just a simple folder and has nothing to do with web server. The destination of the symlink is a shared folder using virtualbox so is of type `vboxfs`. When I boot the vm in linux host its works because it can create the symlink and does not work when I boot in windows host. – Starx Oct 23 '16 at 14:49