mirror of
https://github.com/rommapp/romm.git
synced 2026-12-02 10:08:40 +01:00
cleanup
This commit is contained in:
@@ -287,20 +287,23 @@ async def _identify_rom(
|
||||
"url_screenshots": [],
|
||||
}
|
||||
|
||||
calculate_hashes = not cm.get_config().SKIP_HASH_CALCULATION
|
||||
|
||||
newly_added: bool = rom is None
|
||||
reassociated: bool = False
|
||||
files_built: bool = False
|
||||
|
||||
if rom is None:
|
||||
# No entry matches this filename. Before treating it as brand new, hash
|
||||
# No entry matches this filename. Before treating it as new, hash
|
||||
# the files and check whether they belong to an existing entry that went
|
||||
# missing (a renamed or moved ROM), so its collections, notes, and
|
||||
# uploaded assets carry over instead of being orphaned on a duplicate.
|
||||
calculate_hashes = not cm.get_config().SKIP_HASH_CALCULATION
|
||||
candidate = Rom(**rom_attrs)
|
||||
candidate.platform = platform
|
||||
parsed_rom_files = await fs_rom_handler.get_rom_files(
|
||||
candidate, calculate_hashes=calculate_hashes
|
||||
Rom(
|
||||
**rom_attrs,
|
||||
platform=platform,
|
||||
),
|
||||
calculate_hashes=calculate_hashes,
|
||||
)
|
||||
fs_rom.update(
|
||||
{
|
||||
@@ -320,8 +323,7 @@ async def _identify_rom(
|
||||
sha1_hash=parsed_rom_files.sha1_hash,
|
||||
)
|
||||
if missing_match is not None:
|
||||
# Move the existing entry onto the new file, clearing its missing
|
||||
# state. User data (collections, notes, assets) stays linked by id.
|
||||
# Move the existing entry onto the new file, clearing its missing state.
|
||||
rom = db_rom_handler.update_rom(
|
||||
missing_match.id,
|
||||
{
|
||||
@@ -361,7 +363,6 @@ async def _identify_rom(
|
||||
)
|
||||
if should_update_files and not files_built:
|
||||
# Get hash calculation setting from config
|
||||
calculate_hashes = not cm.get_config().SKIP_HASH_CALCULATION
|
||||
if calculate_hashes:
|
||||
log.debug(f"Calculating file hashes for {rom.fs_name}...")
|
||||
|
||||
|
||||
@@ -2235,13 +2235,8 @@ class DBRomsHandler(DBBaseHandler):
|
||||
Used during scanning to reassociate a renamed or moved file with its
|
||||
existing entry (preserving collections, notes, and assets) instead of
|
||||
creating a duplicate. Requires the CRC, MD5, and SHA1 hashes to all
|
||||
match, so a lone CRC32 collision can't move an unrelated entry onto the
|
||||
file. Any missing hash yields no match, so non-hashable platforms and
|
||||
match. Any missing hash yields no match, so non-hashable platforms and
|
||||
pre-hash entries safely fall back to creating a new entry.
|
||||
|
||||
Returns None when more than one missing entry matches: an ambiguous set
|
||||
(e.g. duplicate content stored twice) has no correct target, so we
|
||||
create a new entry rather than move user data onto an arbitrary row.
|
||||
"""
|
||||
if not (crc_hash and md5_hash and sha1_hash):
|
||||
return None
|
||||
@@ -2260,6 +2255,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
.limit(2)
|
||||
).all()
|
||||
|
||||
# Return None when more than one match to avoid ambiguity.
|
||||
return matches[0] if len(matches) == 1 else None
|
||||
|
||||
def _collect_filter_values(
|
||||
|
||||
Reference in New Issue
Block a user