Skip to content

Renaming an image deletes its torrent without recreating it #30

Description

@TomlDev

LinboImage.rename() deletes the image's .torrent and never creates the replacement, so a renamed image is left without a torrent.

Where

usr/lib/python3/dist-packages/linuxmusterTools/linbo/images.py, in rename() (lines 247-251 on master today):

# Need to generate a new torrent file
if extra == "torrent":
    os.unlink(actual)

    continue

The comment states the intent, but nothing creates the new torrent. linbo-torrent is invoked exactly once in the whole file, and only to stop:

subprocess.check_output(['/usr/sbin/linbo-torrent', 'stop', os.path.join(self.path, f'{self.image}.torrent')])

Deleting rather than renaming is right in itself, since a torrent embeds the file name it describes. What is missing is the follow-up create.

Effect

After a rename through the API the image directory holds .qcow2, .desc, .info, .macct, .hash and .reg under the new name, and no .torrent at all. Groups configured with DownloadType = torrent have no torrent for that image any more. Renaming the image back does not bring it back, because the file is gone rather than orphaned under the old name.

Reproduce

  1. Take an image that has a .torrent next to it.
  2. Rename it through the API (POST /v1/linbo/images/{name}/rename).
  3. ls /srv/linbo/images/<new name>/ — every other sidecar is renamed, the torrent is absent.

Observed on Tools 7.4.14, LINBO 7.4.12, API 7.4.11.

Suggested fix

/usr/sbin/linbo-torrent already has the verb:

linbo-torrent create <image_file>

Its create() rebuilds the torrent, saves the hash and starts seeding. A _torrent_create() helper mirroring the existing _torrent_stop(), called after the rename completes, restores the previous state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions