+'new' as op,
+ printf('%s-%s-%s', PFI.package, PFI.version, PFI.release) as pkgid,
+ PFI.path, PFI.username, PFI.uid, PFI.groupname, PFI.gid, PFI.mode,
+ PFI.filetype, PFI.mtime, PFI.hash,
+ PFI.configuration
+ -- + case when PFC.configuration = 1 then 2 else 0 end
+ as configuration,
+ PFI.target, PFI.device, null as ohash,
+ printf('%s:%s:%s:%s', PFI.filetype, PFI.mode, PFI.username, PFI.groupname) as mds,
+ --printf('%s:%s:%s:%s', PFC.filetype, PFC.mode, PFC.username, PFC.groupname) as omds
+ null as omds
+from
+
+packagefiles PFI
+join packages PI
+on PFI.package = PI.package and PFI.version = PI.version and PFI.release = PI.release
+
+/*
+left join packagefiles PFC on PFI.path = PFC.path
+
+left join packages PC
+on (PFI.package is not PC.package or PFI.release is not PC.release or PC.version is not PFI.version)
+and PC.status in ('installed','removing','updating')
+and PFC.package = PC.package and PFC.version = PC.version and PFC.release = PC.release
+*/
+
+where
+PI.status = 'installing'
+and
+not exists (select PFC.path
+ from packagefiles PFC
+ join packages PC
+on PFC.package = PC.package and PFC.version = PC.version and PFC.release = PC.release
+ where PFC.path = PFI.path
+ and PC.status in ('installed','removing','updating')
+)
+
+/*
+(PFC.path is null
+ or
+PC.status not in ('installed','removing','updating')
+)
+*/
+
+union
+select
+case
+when PFI.filetype is not 'l'
+ and PFI.filetype is PFC.filetype