Skip to content

Commit

Permalink
fallback to shutil.move when pathlib.rename fails fix #291 (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Oct 22, 2019
1 parent 1f83ece commit d3deae8
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions modules/api/auth.py
Expand Up @@ -2,30 +2,31 @@

# Standard library
import logging
from pathlib import Path
import shutil
import time
from functools import partial
from pathlib import Path

# PyQGIS
from qgis.gui import QgsMessageBar

# PyQT
from qgis.PyQt.QtCore import (
QSettings,
QCoreApplication,
QTranslator,
qVersion,
QObject,
QSettings,
QTranslator,
pyqtSignal,
qVersion,
)

# PyQGIS
from qgis.gui import QgsMessageBar
# UI class
from ...ui.auth.dlg_authentication import IsogeoAuthentication

# Plugin modules
from ..tools import IsogeoPlgTools
from ..user_inform import UserInformer

# UI class
from ...ui.auth.dlg_authentication import IsogeoAuthentication

# ############################################################################
# ########## Globals ###############
# ##################################
Expand Down Expand Up @@ -364,7 +365,7 @@ def credentials_uploader(self):
)
self.ui_auth_form.btn_ok_cancel.buttons()[0].setEnabled(False)
return False
# move credentials file into the plugin file structure
# rename existing credentials file with prefix 'old_' and datetime as suffix
dest_path = self.cred_filepath
if dest_path.is_file():
logger.debug(
Expand All @@ -379,13 +380,24 @@ def credentials_uploader(self):

else:
pass

# mave new credentials file to the _auth subfolder
try:
selected_file.rename(dest_path)
selected_file.rename(dest_path) # using pathlib.Path (= os.rename)
logger.debug(
"Selected credentials file has been moved into plugin" "_auth subfolder"
"Selected credentials file has been moved into plugin _auth subfolder"
)
except Exception as e:
logger.debug("Fail to rename authentication file : {}".format(e))
except OSError as exc:
logger.error(
"Move new file raised: {}. Maybe because of moving from a "
"different disk drive. Trying with lower-level lib... "
"See: https://github.com/isogeo/isogeo-plugin-qgis/issues/291 ".format(
exc
)
)
shutil.move(selected_file, dest_path)
except Exception as exc:
logger.error("Failed to move authentication file: {}".format(exc))
self.auth_sig.emit("path")
self.ui_auth_form.btn_browse_credentials.fileChanged.connect(
self.credentials_uploader
Expand Down

0 comments on commit d3deae8

Please sign in to comment.