fix 'SaveAs' to non-empty directory and directory without write permissions
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Mon, 14 Jan 2019 12:17:48 +0300
changeset 2505 3487fd4fb9bf
parent 2504 f3aced6c5f8b
child 2506 8dbdf20f795b
fix 'SaveAs' to non-empty directory and directory without write permissions
ProjectController.py
--- a/ProjectController.py	Sat Jan 12 15:02:17 2019 +0300
+++ b/ProjectController.py	Mon Jan 14 12:17:48 2019 +0300
@@ -549,10 +549,19 @@
             dialog.ShowModal()
             return False
         else:
-            plc_file = os.path.join(new_project_path, "plc.xml")
-            if os.path.isfile(plc_file):
-                message = (
-                    _("Selected directory already contains another project. Overwrite? \n"))
+            if not CheckPathPerm(new_project_path):
+                dialog = wx.MessageDialog(
+                    self.AppFrame,
+                    _('No write permissions in selected directory! \n'),
+                    _("Error"), wx.OK | wx.ICON_ERROR)
+                dialog.ShowModal()
+                return False
+            if not os.path.isdir(new_project_path) or len(os.listdir(new_project_path)) > 0:
+                plc_file = os.path.join(new_project_path, "plc.xml")
+                if os.path.isfile(plc_file):
+                    message = _("Selected directory already contains another project. Overwrite? \n")
+                else:
+                    message = _("Selected directory isn't empty. Continue? \n")
                 dialog = wx.MessageDialog(
                     self.AppFrame, message, _("Error"), wx.YES_NO | wx.ICON_ERROR)
                 answer = dialog.ShowModal()