Prevent local storage setup on non-mounted paths

Fixes #269
This commit is contained in:
Joseph Schorr 2015-07-27 14:32:02 -04:00
parent 66aaf0e4a2
commit 26ae629189
3 changed files with 24 additions and 1 deletions

View file

@ -3,6 +3,7 @@ import shutil
import hashlib
import io
import logging
import psutil
from uuid import uuid4
@ -145,5 +146,20 @@ class LocalStorage(BaseStorageV2):
else:
logger.debug('Content already exists at path: %s', final_path_abs)
def validate(self):
# Load the set of disk mounts.
try:
mounts = psutil.disk_partitions(all=True)
except:
logger.exception('Could not load disk partitions')
return
# Verify that the storage's root path is under a mounted Docker volume.
for mount in mounts:
if mount.mountpoint != '/' and self._root_path.startswith(mount.mountpoint):
if mount.device == 'tmpfs':
return
raise Exception('Storage path %s is not under a mounted volume.\n\n'
'Registry data must be stored under a mounted volume '
'to prevent data loss' % self._root_path)