diff --git a/entry.sh b/entry.sh index 4c6cb22c..bea077a1 100755 --- a/entry.sh +++ b/entry.sh @@ -12,7 +12,7 @@ rm -f /var/run/avahi-daemon/pid # already be using to take an update lock, so we symlink it to the new # location so that the supervisor can see it [ -d /mnt/root/tmp/resin-supervisor ] && - ( [ -d /mnt/root/tmp/balena-supervisor ] || ln ./resin-supervisor /mnt/root/tmp/balena-supervisor ) + ( [ -d /mnt/root/tmp/balena-supervisor ] || ln -s ./resin-supervisor /mnt/root/tmp/balena-supervisor ) # Otherwise, if the lockfiles directory doesn't exist [ -d /mnt/root/tmp/balena-supervisor ] || diff --git a/src/application-manager.coffee b/src/application-manager.coffee index dda00e96..a399bbc9 100644 --- a/src/application-manager.coffee +++ b/src/application-manager.coffee @@ -200,8 +200,7 @@ module.exports = class ApplicationManager extends EventEmitter @services.getStatus() @images.getStatus(localMode) @config.get('currentCommit') - @db.models('app').select([ 'appId', 'releaseId', 'commit' ]) - (services, images, currentCommit, targetApps) -> + (services, images, currentCommit) -> apps = {} dependent = {} releaseId = null @@ -808,10 +807,15 @@ module.exports = class ApplicationManager extends EventEmitter _.map app.services, (service) -> img = _.find(available, { dockerImageId: service.config.image, imageId: service.imageId }) ? _.find(available, { dockerImageId: service.config.image }) return _.omit(img, [ 'dockerImageId', 'id' ]) + allImageDockerIdsForTargetApp = (app) -> + _(app.services).map((svc) -> [ svc.imageName, svc.config.image ]) + .filter((img) -> img[1]?) + .value() availableWithoutIds = _.map(available, (image) -> _.omit(image, [ 'dockerImageId', 'id' ])) currentImages = _.flatMap(current.local.apps, allImagesForCurrentApp) targetImages = _.flatMap(target.local.apps, allImagesForTargetApp) + targetImageDockerIds = _.fromPairs(_.flatMap(target.local.apps, allImageDockerIdsForTargetApp)) availableAndUnused = _.filter availableWithoutIds, (image) -> !_.some currentImages.concat(targetImages), (imageInUse) -> _.isEqual(image, imageInUse) @@ -823,8 +827,16 @@ module.exports = class ApplicationManager extends EventEmitter imagesToSave = [] if !localMode imagesToSave = _.filter targetImages, (targetImage) => - _.some(available, (availableImage) => @images.isSameImage(availableImage, targetImage)) and - !_.some availableWithoutIds, (img) -> _.isEqual(img, targetImage) + isActuallyAvailable = _.some( + available, (availableImage) => + if @images.isSameImage(availableImage, targetImage) + return true + if availableImage.dockerImageId == targetImageDockerIds[targetImage.name] + return true + return false + ) + isNotSaved = !_.some availableWithoutIds, (img) -> _.isEqual(img, targetImage) + return isActuallyAvailable and isNotSaved deltaSources = _.map imagesToDownload, (image) => return @bestDeltaSource(image, available)