diff piecrust/pipelines/base.py @ 1051:971b4d67e82a

serve: Fix problems with assets disappearing between servings. When an asset file changes, its source's pipeline is re-run. But that created a bake record that only had that pipeline's output, so the other outputs were incorrectly considered empty and therefore any stray files were removed. Now we copy over bake records for the pipelines we don't run.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 26 Jan 2018 18:05:02 -0800
parents fa489c5e829e
children 5f97b5b59dfe
line wrap: on
line diff
--- a/piecrust/pipelines/base.py	Fri Jan 26 18:02:07 2018 -0800
+++ b/piecrust/pipelines/base.py	Fri Jan 26 18:05:02 2018 -0800
@@ -283,10 +283,22 @@
                         pass
                     logger.info('[delete] %s' % path)
 
-    def collapseRecords(self):
+    def collapseRecords(self, keep_unused_records=False):
+        seen_records = []
         for ppinfo in self.getPipelineInfos():
             ctx = PipelineCollapseRecordContext(ppinfo.record_history)
             ppinfo.pipeline.collapseRecords(ctx)
+            seen_records.append(ppinfo.pipeline.record_name)
+
+        if keep_unused_records:
+            cur_recs = self.record_histories.current
+            prev_recs = self.record_histories.previous
+            for prev_rec in prev_recs.records:
+                if prev_rec.name in seen_records:
+                    continue
+
+                logger.debug("Keeping record: %s" % prev_rec.name)
+                cur_recs.records.append(prev_rec)
 
     def shutdownPipelines(self):
         for ppinfo in self.getPipelineInfos():