tags 869557 + patch thanks Hi,
> apt: please make the output of apt-ftparchive reproducible *Extremely* WIP patch attached: commit 489251d0bcf32883e9028aa0278168c167f2f6e9 Author: Chris Lamb <la...@debian.org> Date: Mon Jul 24 15:04:03 2017 +0100 Make the output of ftp-archive reproducible by sorting non-deterministic file orders prior to output. (Closes: #869557) ftparchive/writer.cc | 19 ++++++++++++++++++- ftparchive/writer.h | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) Regards, -- ,''`. : :' : Chris Lamb, Debian Project Leader `. `'` la...@debian.org / chris-lamb.co.uk `-
>From 489251d0bcf32883e9028aa0278168c167f2f6e9 Mon Sep 17 00:00:00 2001 From: Chris Lamb <la...@debian.org> Date: Mon, 24 Jul 2017 15:04:03 +0100 Subject: [PATCH] Make the output of ftp-archive reproducible by sorting non-deterministic file orders prior to output. (Closes: #869557) --- ftparchive/writer.cc | 19 ++++++++++++++++++- ftparchive/writer.h | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index 5773f3aec..9c081c567 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -124,7 +124,6 @@ int FTWScanner::ScannerFTW(const char *File,const struct stat * /*sb*/,int Flag) int FTWScanner::ScannerFile(const char *File, bool const &ReadLink) { const char *LastComponent = strrchr(File, '/'); - char *RealPath = NULL; if (LastComponent == NULL) LastComponent = File; @@ -140,10 +139,18 @@ int FTWScanner::ScannerFile(const char *File, bool const &ReadLink) if (I == Owner->Patterns.end()) return 0; + Owner->FilesToProcess.push_back(std::pair<string, bool>(File, ReadLink)); + + return 0; +} + +int FTWScanner::ProcessFile(const char *File, bool const &ReadLink) +{ /* Process it. If the file is a link then resolve it into an absolute name.. This works best if the directory components the scanner are given are not links themselves. */ char Jnk[2]; + char *RealPath = NULL; Owner->OriginalPath = File; if (ReadLink && readlink(File,Jnk,sizeof(Jnk)) != -1 && @@ -209,6 +216,16 @@ bool FTWScanner::RecursiveScan(string const &Dir) _error->Errno("ftw",_("Tree walking failed")); return false; } + + sort(Owner->FilesToProcess.begin(), Owner->FilesToProcess.end(), [](const pair<string, bool>& a, const pair<string, bool>& b) { + return a.first.compare(b.first); + }); + + for (const pair<string, bool> &it : Owner->FilesToProcess) + { + if (Owner->ProcessFile(it.first.c_str(), it.second) != 0) + return false; + } return true; } diff --git a/ftparchive/writer.h b/ftparchive/writer.h index ea4c66da4..4cb775515 100644 --- a/ftparchive/writer.h +++ b/ftparchive/writer.h @@ -23,6 +23,7 @@ #include <set> #include <stdlib.h> #include <sys/types.h> +#include <utility> #include "contents.h" #include "cachedb.h" @@ -39,6 +40,7 @@ class FTWScanner { protected: vector<string> Patterns; + vector<std::pair<string,bool> > FilesToProcess; string Arch; bool IncludeArchAll; const char *OriginalPath; @@ -50,6 +52,7 @@ class FTWScanner static FTWScanner *Owner; static int ScannerFTW(const char *File,const struct stat *sb,int Flag); static int ScannerFile(const char *File, bool const &ReadLink); + static int ProcessFile(const char *File, bool const &ReadLink); bool Delink(string &FileName,const char *OriginalPath, unsigned long long &Bytes,unsigned long long const &FileSize); -- 2.13.3