#3886 Raise an error on missing build directory
Merged 7 months ago by tkopecek. Opened 9 months ago by tkopecek.
tkopecek/koji strict-move  into  master

file modified
+12 -13
@@ -5891,21 +5891,21 @@ 

              raise koji.GenericError("Unexpected cross-volume content: %s" % checkdir)

  

      # First copy the build dir(s)

-     dir_moves = []

      old_binfo = binfo.copy()

      binfo['volume_id'] = volinfo['id']

      binfo['volume_name'] = volinfo['name']

      olddir = koji.pathinfo.build(old_binfo)

-     if os.path.exists(olddir):

-         newdir = koji.pathinfo.build(binfo)

-         dir_moves.append([olddir, newdir])

-     for olddir, newdir in dir_moves:

-         # Remove old symlink if copying to base volume

-         if volinfo['name'] == 'DEFAULT' or volinfo['name'] is None:

-             if os.path.islink(newdir):

-                 os.unlink(newdir)

-         koji.ensuredir(os.path.dirname(newdir))

-         shutil.copytree(olddir, newdir, symlinks=True)

+     newdir = koji.pathinfo.build(binfo)

+     if not os.path.exists(olddir):

+         raise koji.GenericError(f"Build directory missing: {olddir}")

+     if not os.path.isdir(olddir):

+         raise koji.GenericError(f"Not a directory: {olddir}")

+     # Remove old symlink if copying to base volume

+     if volinfo['name'] == 'DEFAULT' or volinfo['name'] is None:

+         if os.path.islink(newdir):

+             os.unlink(newdir)

+     koji.ensuredir(os.path.dirname(newdir))

+     shutil.copytree(olddir, newdir, symlinks=True)

  

      # Second, update the db

      koji.plugin.run_callbacks('preBuildStateChange', attribute='volume_id',
@@ -5917,8 +5917,7 @@ 

          set_tag_update(tag['id'], 'VOLUME_CHANGE')

  

      # Third, delete the old content

-     for olddir, newdir in dir_moves:

-         koji.util.rmtree(olddir)

+     koji.util.rmtree(olddir)

  

      # Fourth, maintain a symlink if appropriate

      if volinfo['name'] and volinfo['name'] != 'DEFAULT':

setBuildVolume will pass to later stage and traceback on undefined newdir.

setBuildVolume will pass to later stage and traceback on undefined newdir.

This is missing the deeper issue -- newdir is a loop variable that is being relied upon after the loop has terminated. Granted, dir_moves can only have one or zero entries with the current code. (It looks like this code layout comes from the old days when maven builds were in a separate dir structure, so we had multiple dirs to move).

Also, I think we can fail here even if not strict since this this falls in the "shouldn't happen" category.

rebased onto 385e46796b4117ff6fd71be70c84ae74552a5bdd

8 months ago

rebased onto a52b59a

8 months ago

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

7 months ago

Metadata Update from @relias-redhat:
- Pull-request tagged with: testing-done

7 months ago

Commit 96f784c fixes this pull-request

Pull-Request has been merged by tkopecek

7 months ago