-preserved as (
- select BASE.*, 'preserved' as rstatus
- from packagefiles_status BASE
- join elflibraries EL on EL.file = BASE.hash
- where
- BASE.status in ('removed', 'updated')
- and BASE.hash in (select hash from packagefiles_status where
- status in ('installed'))
-),
-syncstatus as (
- select distinct BASE.*,
- case when P.status = 'installing' and BASE.status = 'installed'
- then 'updating'
- when BASE.status in ('removed','updated')
- and BASE.path in (select path from preserved) then
- 'preserved'
- else
- BASE.status
- end as rstatus
- from packagefiles_status BASE
- left join packages P on P.package = BASE.package
- and BASE.status in ('installed', 'removing')
- and P.status = 'installing'
-),
--- new file: in installing, not in installed or updating or removing
-newfiles as (
- select distinct
- path,username,uid,groupname,gid,mode,filetype,mtime,hash,
- configuration,target,device, null as ohash
- from syncstatus SS
- where path not in (select path from syncstatus where
- rstatus in ('installed', 'updating', 'removing')
- )
- and rstatus in ('installing')
-),
--- modified: retained, but with different metadata
-modified as (
- select distinct
- SS.path,
- SS.username, SS.uid, SS.groupname, SS.gid, SS.mode, SS.filetype,
- SS.mtime, SS.hash, SS.configuration, SS.target, SS.device,
- OS.hash as ohash, SS.mds, OS.mds as omds
- from syncstatus SS
- join syncstatus OS
- on SS.path = OS.path and SS.pkgid is not OS.pkgid
- -- preserved?
- and OS.rstatus in ('installed','updating','removing')
- and (SS.mds is not OS.mds or SS.hash is not OS.hash)
- where
- SS.rstatus in ('installing')
-),
--- preserve: libraries needed by something in installed or installing
-needed as (
- select distinct
- ED.library
- from elfdeps ED
- where status in ('installed', 'installing')
- and library is not null
-),