[cwctl] do only clean static data dir content (closes #17069762) 3.25
authorDavid Douard <david.douard@logilab.fr>
Tue, 04 Apr 2017 11:41:23 +0200
branch3.25
changeset 12140 20035170160c
parent 12139 b5be819872bb
child 12141 29d032bb70d8
[cwctl] do only clean static data dir content (closes #17069762) deleting the directory itself is useless and may be a problem in automated deployment environments (user may not have permissions to delete or create that directory).
cubicweb/web/webctl.py
--- a/cubicweb/web/webctl.py	Mon Apr 03 14:43:44 2017 +0200
+++ b/cubicweb/web/webctl.py	Tue Apr 04 11:41:23 2017 +0200
@@ -39,6 +39,17 @@
     from shutil import copytree as linkdir
 
 
+def rmtreecontent(dst):
+    """Delete the content of the dst directory (but NOT the directory
+       itself)"""
+    for fname in os.listdir(dst):
+        fpath = osp.join(dst, fname)
+        if osp.isfile(fpath):
+            os.unlink(fpath)
+        else:
+            rmtree(fpath)
+
+
 class WebCreateHandler(CommandHandler):
     cmdname = 'create'
 
@@ -70,7 +81,7 @@
                      ASK.confirm('Remove existing data directory %s?' % dest))):
                 raise ExecutionError('Directory %s already exists. '
                                      'Remove it first.' % dest)
-            rmtree(dest)
+            rmtreecontent(dest)
         config.quick_start = True # notify this is not a regular start
         # list all resources (no matter their order)
         resources = set()