From 9f9cb1c7913869bcba39a0867ed3a3e33f69c734 Mon Sep 17 00:00:00 2001
From: Paul Colomiets <paul@colomiets.name>
Date: Wed, 9 Apr 2014 16:15:19 +0300
Subject: [PATCH] Implement sorting of synced_folders

It's useful if you want to mount something inside /vagrant or if you
have some another mount in some synced folder.

This piece of code is extracted from virtualbox driver.
---
 lib/vagrant-lxc/synced_folder.rb | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/vagrant-lxc/synced_folder.rb b/lib/vagrant-lxc/synced_folder.rb
index 855b40b..1130622 100644
--- a/lib/vagrant-lxc/synced_folder.rb
+++ b/lib/vagrant-lxc/synced_folder.rb
@@ -8,6 +8,15 @@ module Vagrant
 
       def prepare(machine, folders, _opts)
         machine.ui.output(I18n.t("vagrant.actions.lxc.share_folders.preparing"))
+        # short guestpaths first, so we don't step on ourselves
+        folders = folders.sort_by do |id, data|
+          if data[:guestpath]
+            data[:guestpath].length
+          else
+            # A long enough path to just do this at the end.
+            10000
+          end
+        end
 
         folders.each do |id, data|
           host_path  = Pathname.new(File.expand_path(data[:hostpath], machine.env.root_path))