Skip to content

Commit

Permalink
Copy mount_dir to remote, if remote is empty, and mount_dir has files.
Browse files Browse the repository at this point in the history
…Closes #7
  • Loading branch information
macropin committed Mar 8, 2016
1 parent 97d3742 commit 265c3a9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion voltgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import shutil
import re
import tempfile
from distutils.dir_util import copy_tree


__version__ = 1

Expand Down Expand Up @@ -207,6 +209,16 @@ def handle(self):
os.makedirs(remote_dir)
if remote_dir != self.remote:
os.chown(remote_dir, self.mount_uid, self.mount_gid)
# Copy mount_dir to remote, if remote is empty, and mount_dir has files
if not os.listdir(remote_dir) and os.listdir(mount_dir):
# use copy_tree because shutil.copytree doesn't like it when the dst exists
copy_tree(mount_dir, remote_dir)
# Fix permissions recursively
for root, dirs, files in os.walk(remote_dir):
for item in dirs:
os.chown(os.path.join(root, item), self.mount_uid, self.mount_gid)
for item in files:
os.chown(os.path.join(root, item), self.mount_uid, self.mount_gid)
# Delete mount_dir if exists. Create symlink to remote_dir
if os.path.isfile(mount_dir) or os.path.islink(mount_dir):
os.remove(mount_dir)
Expand Down Expand Up @@ -271,7 +283,7 @@ def execute(arg, user, group):
for e in ['HOME',]:
print("Unsetting %s" % e)
del os.environ[e]

# Load config
c = ConfigManager(VG_CONF_PATH)
c.write_envs()
Expand Down

0 comments on commit 265c3a9

Please sign in to comment.