forked from AimRT/AimRT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: aimrt_cli trans will first repair the aimrtbag (AimRT#112)
* fix(bag): optimize bag file processing workflow - Add handling for missing files in PlaybackAction, ignore non-existent files - Add bag_recover.py script for repairing corrupted bag files - Modify rosbag_trans.py to add file existence check and repair steps - Add index creation and transaction handling in AimrtbagToRos2 to improve conversion efficiency * build(bag_recover): update version * fix: rename the file * fix: opt the code
- Loading branch information
1 parent
18d45db
commit b41416c
Showing
4 changed files
with
66 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import subprocess | ||
import shutil | ||
import os | ||
|
||
|
||
def repair_bag(bag_path: str): | ||
try: | ||
journal_files = [f for f in os.listdir(bag_path) if f.endswith("-journal")] | ||
if not journal_files: | ||
print(f"there is no journal file in {bag_path}") | ||
return | ||
|
||
print(f"detect {len(journal_files)} journal files, start to repair") | ||
|
||
for journal_file in journal_files: | ||
journal_file_name = journal_file.split("-")[0] | ||
journal_path = os.path.join(bag_path, journal_file_name) | ||
print(f"journal_path: {journal_path}") | ||
|
||
backup_path = f"{journal_path}.bak" | ||
recover_path = os.path.join(bag_path, "recovered.db3") | ||
shutil.copy2(journal_path, backup_path) | ||
|
||
try: | ||
cmd = f'sqlite3 "{journal_path}" ".recover" | sqlite3 "{recover_path}"' | ||
subprocess.run(cmd, shell=True, check=True) | ||
|
||
if os.path.exists(recover_path): | ||
os.replace(recover_path, journal_path) | ||
print(f"{journal_path} repair done \n") | ||
|
||
except subprocess.CalledProcessError as e: | ||
print(f"database repair failed: {e.stderr.decode()}") | ||
finally: | ||
if os.path.exists(backup_path): | ||
os.remove(backup_path) | ||
|
||
except Exception as e: | ||
print(f"repair failed: {str(e)}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters