--- every path in updating is either remove or no-op
-union
-select 'remove',
- printf('%s-%s-%s', PFU.package, PFU.version, PFU.release) as pkgid,
- PFU.path,
- PFU.username, PFU.uid, PFU.groupname, PFU.gid, PFU.mode, PFU.filetype,
- PFU.mtime, PFU.hash,
- PFU.configuration + case when PFC.configuration = 1 then 2 else 0 end
- as configuration,
- PFU.target, PFU.device,
- null as ohash,
- printf('%s:%s:%s:%s', PFU.filetype, PFU.mode, PFU.username, PFU.groupname) as mds,
- null as omds
-from packagefiles PFU
-join packages PU
-on PFU.package = PU.package and PFU.version = PU.version and PFU.release = PU.release
--- inner join because the installing package must exist or this shouldn't
--- be an 'updating' package
-join packages P on PU.package = P.package and P.status = 'installing'
-left join packagefiles PFI on
- PFI.package = P.package
- and PFI.version = P.version
- and PFI.release = P.release
- and PFI.path = PFU.path
-
--- handle paths owned by other installed packages
-left join packages PI on PI.status = 'installed'
-left join packagefiles PFC
-on PFC.package = PI.package and PFC.version = PI.version and PFC.release = PI.release and PFC.path = PFU.path
-
-where
-PU.status in ('updating')
-and PFI.path is null
-and PFC.path is null
-and PFU.path not in (select path from preserve)
-
--- every path in removing is either remove or no-op