1111import os
1212import json
1313
14- from flask import Response , request , render_template , url_for , current_app
14+ from flask import Response , request , render_template , current_app
1515from flask_babel import gettext
1616from flask_login import current_user
1717
1818from pgadmin .user_login_check import pga_login_required
19- from pgadmin .utils import PgAdminModule
19+ from pgadmin .utils import PgAdminModule , get_complete_file_path
2020from pgadmin .utils .ajax import make_json_response , bad_request ,\
2121 success_return , internal_server_error
2222from pgadmin .utils .menu import MenuItem
2626from .utils import get_dialog_type , get_file_type_setting
2727from cryptography .fernet import Fernet
2828import hashlib
29- from urllib .parse import unquote
30- from pgadmin .utils .preferences import Preferences
31- from pgadmin .utils import get_storage_directory
3229
3330MODULE_NAME = 'settings'
3431
@@ -284,8 +281,7 @@ def save_application_state():
284281 if 'connection_info' in data else None
285282 if ('open_file_name' in connection_info and
286283 connection_info ['open_file_name' ]):
287- file_path = get_file_path (connection_info ['open_file_name' ],
288- connection_info ['storage' ])
284+ file_path = get_complete_file_path (connection_info ['open_file_name' ])
289285 connection_info ['last_saved_file_hash' ] = (
290286 get_last_saved_file_hash (file_path , trans_id ))
291287
@@ -323,7 +319,7 @@ def get_last_saved_file_hash(file_path, trans_id):
323319 last_saved_file_hash = connection_info ['last_saved_file_hash' ]
324320
325321 if file_hash_update_require :
326- last_saved_file_hash = compute_sha256_large_file (file_path )
322+ last_saved_file_hash = compute_md5_hash_file (file_path )
327323
328324 return last_saved_file_hash
329325
@@ -348,8 +344,8 @@ def get_application_state():
348344 connection_info = row .connection_info
349345 if ('open_file_name' in connection_info and
350346 connection_info ['open_file_name' ]):
351- file_path = get_file_path (
352- connection_info ['open_file_name' ], connection_info [ 'storage' ] )
347+ file_path = get_complete_file_path (
348+ connection_info ['open_file_name' ])
353349 file_deleted = False if os .path .exists (file_path ) else True
354350 connection_info ['file_deleted' ] = file_deleted
355351
@@ -374,31 +370,6 @@ def get_application_state():
374370 )
375371
376372
377- def get_file_path (file_name , storage ):
378-
379- file_path = unquote (file_name )
380-
381- # get the current storage from request if available
382- # or get it from last_storage preference.
383- if storage :
384- storage_folder = storage
385- else :
386- storage_folder = Preferences .module ('file_manager' ).preference (
387- 'last_storage' ).get ()
388-
389- # retrieve storage directory path
390- storage_manager_path = get_storage_directory (
391- shared_storage = storage_folder )
392-
393- if storage_manager_path :
394- # generate full path of file
395- file_path = os .path .join (
396- storage_manager_path ,
397- file_path .lstrip ('/' ).lstrip ('\\ ' )
398- )
399- return file_path
400-
401-
402373@blueprint .route (
403374 '/delete_application_state/' ,
404375 methods = ["DELETE" ], endpoint = 'delete_application_state' )
@@ -439,20 +410,8 @@ def delete_tool_data(trans_id=None):
439410 return False , str (e )
440411
441412
442- def compute_sha256_large_data_in_memory (data , chunk_size = 8192 ):
443- """Hash large data (in-memory) by processing in chunks."""
444- md5_hash = hashlib .md5 ()
445- # Process data in 8 KB chunks
446- string_data = json .loads (data )
447- for i in range (0 , len (string_data ), chunk_size ):
448- chunk = string_data [i :i + chunk_size ]
449- md5_hash .update (chunk .encode ("utf-8" ))
450-
451- return md5_hash .hexdigest ()
452-
453-
454- def compute_sha256_large_file (file_path , chunk_size = 8192 ):
455- """Compute SHA-256 hash for large files by reading in chunks."""
413+ def compute_md5_hash_file (file_path , chunk_size = 8192 ):
414+ """Compute md5 hash for large files by reading in chunks."""
456415 md5_hash = hashlib .md5 ()
457416
458417 # Open the file in binary mode
@@ -465,7 +424,7 @@ def compute_sha256_large_file(file_path, chunk_size=8192):
465424
466425
467426def check_external_file_changes (file_path , last_saved_file_hash ):
468- current_file_hash = compute_sha256_large_file (file_path )
427+ current_file_hash = compute_md5_hash_file (file_path )
469428 if current_file_hash != last_saved_file_hash :
470429 return True
471430 return False
0 commit comments