Skip to content

Commit

Permalink
Merge pull request #121 from opengisch/fix_file_not_found
Browse files Browse the repository at this point in the history
Only calculate md5sum if offline editing done
  • Loading branch information
m-kuhn authored Jul 24, 2019
2 parents 3dd612a + 9e86d92 commit 7f38091
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 1 addition & 2 deletions qfieldsync/dialogs/synchronize_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def start_synchronization(self):
current_import_file_checksum = import_file_checksum(qfield_folder)
imported_files_checksums = import_checksums_of_project(qfield_folder)

if imported_files_checksums and current_import_file_checksum in imported_files_checksums:
if imported_files_checksums and current_import_file_checksum and current_import_file_checksum in imported_files_checksums:
message = self.tr("Data from this file are already synchronized with the original project.")
raise NoProjectFoundError(message)
qgs_file = get_project_in_folder(qfield_folder)
Expand All @@ -84,7 +84,6 @@ def start_synchronization(self):
ProjectConfiguration(QgsProject.instance()).imported_files_checksums = imported_files_checksums
QgsProject.instance().write()
self.iface.messageBar().pushInfo('QFieldSync', self.tr(u"Opened original project {}".format(original_project_path)))
print(imported_files_checksums)
else:
self.iface.messageBar().pushInfo('QFieldSync', self.tr(u"The data has been synchronized successfully but the original project ({}) could not be opened. ".format(original_project_path)))
self.close()
Expand Down
10 changes: 7 additions & 3 deletions qfieldsync/utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ def open_folder(path):


def import_file_checksum(folder):
md5sum = None
path = os.path.join(folder, "data.gpkg")
if not os.path.exists(path):
path = os.path.join(folder, "data.sqlite")
with open(path, 'rb') as f:
file_data = f.read()
return hashlib.md5(file_data).hexdigest()
if os.path.exists(path):
with open(path, 'rb') as f:
file_data = f.read()
md5sum = hashlib.md5(file_data).hexdigest()

return md5sum

0 comments on commit 7f38091

Please sign in to comment.