Fix file selection on Windows. Fixes #1319

1) Unable to select sql file through query tool on windows OS. In file_manager.js, we are stripping initial slash '/' from the path obtained, but we should not strip if it is full path like 'c:/path/to/dir/filename.ext'

2) Handle directory path if STORAGE_DIR is None. Proper checks are added.
pull/3/head
Surinder Kumar 2016-06-10 17:06:22 +01:00 committed by Dave Page
parent d9804ae2a2
commit 9e8e3fc787
4 changed files with 24 additions and 10 deletions

View File

@ -245,7 +245,7 @@ class Filemanager(object):
)
self.dir = get_storage_directory()
if isinstance(self.dir, list):
if self.dir is not None and isinstance(self.dir, list):
self.dir = ""
@staticmethod
@ -507,6 +507,8 @@ class Filemanager(object):
"""
path = unquote(path)
if self.dir is None:
self.dir = ""
orig_path = "{0}{1}".format(self.dir, path)
user_dir = path
thefile = {

View File

@ -138,7 +138,9 @@ define([
sel_file = $('.fileinfo tbody tr.selected td p span').attr('title');
}
var newFile = $('.currentpath').val() + sel_file;
newFile = newFile.substr(1);
if (newFile.indexOf('/') == 0) {
newFile = newFile.substr(1);
}
pgAdmin.Browser.Events.trigger('pgadmin-storage:finish_btn:storage_dialog', newFile);
}
removeTransId(trans_id);
@ -249,7 +251,9 @@ define([
sel_file = $('.fileinfo tbody tr.selected td p span').attr('title');
}
var newFile = $('.currentpath').val() + sel_file;
newFile = newFile.substr(1);
if (newFile.indexOf('/') == 0) {
newFile = newFile.substr(1);
}
pgAdmin.Browser.Events.trigger('pgadmin-storage:finish_btn:select_file', newFile);
}
removeTransId(trans_id);
@ -360,7 +364,9 @@ define([
sel_file = $('.fileinfo tbody tr.selected td p span').attr('title');
}
var newFile = $('.currentpath').val() + sel_file;
newFile = newFile.substr(1);
if (newFile.indexOf('/') == 0) {
newFile = newFile.substr(1);
}
pgAdmin.Browser.Events.trigger('pgadmin-storage:finish_btn:select_folder', newFile);
}
removeTransId(trans_id);
@ -468,8 +474,10 @@ define([
$('.replace_file .btn_yes').click(function(self) {
$('.replace_file, .fm_dimmer').hide();
var selected_item = $('.allowed_file_types .create_input input[type="text"]').val(),
sel_item = $('.currentpath').val() + selected_item,
newFile = sel_item.substr(1);
newFile = $('.currentpath').val() + selected_item;
if (newFile.indexOf('/') == 0) {
newFile = newFile.substr(1);
}
pgAdmin.Browser.Events.trigger('pgadmin-storage:finish_btn:create_file', newFile);
$('.file_manager_create_cancel').trigger('click');
});
@ -509,7 +517,9 @@ define([
if (closeEvent.button.text == "{{ _('Create') }}") {
var selected_item = $('.allowed_file_types .create_input input[type="text"]').val();
var newFile = $('.currentpath').val() + selected_item;
newFile = newFile.substr(1);
if (newFile.indexOf('/') == 0) {
newFile = newFile.substr(1);
}
if(!_.isUndefined(selected_item) && selected_item !== '' && this.is_file_exist()) {
this.replace_file();
closeEvent.cancel = true;

View File

@ -1117,6 +1117,8 @@ def load_file():
# retrieve storage directory path
storage_manager_path = get_storage_directory()
if storage_manager_path is None:
storage_manager_path = ""
# generate full path of file
file_path = os.path.join(

View File

@ -61,11 +61,11 @@ def init_app(app):
if storage_dir and not os.path.isdir(storage_dir):
if os.path.exists(storage_dir):
raise Exception(
'The value specified for as the storage directory is not a directory!'
'The path specified for the storage directory is not a directory.'
)
os.makedirs(storage_dir, int('700', 8))
if not os.access(storage_dir, os.W_OK | os.R_OK):
if storage_dir and not os.access(storage_dir, os.W_OK | os.R_OK):
raise Exception(
'The user does not have permission to read, write on the specified storage directory!'
'The user does not have permission to read and write to the specified storage directory.'
)