diff options
| author | Julian Andres Klode <julian.klode@canonical.com> | 2024-11-11 14:06:22 +0100 |
|---|---|---|
| committer | Julian Andres Klode <julian.klode@canonical.com> | 2024-11-20 15:04:28 +0100 |
| commit | 918a13883a6d657bba2b9d786a9468332ab0f06e (patch) | |
| tree | 2e72bc6bb6a164c6ab104ee2111b1a5ab796c1d3 | |
| parent | 709adda89a575e6c542310e6632c090632bb9732 (diff) | |
ftparchive: writer: Remove line length limit on file lists
LP: #2087848
| -rw-r--r-- | ftparchive/writer.cc | 33 | ||||
| -rwxr-xr-x | test/integration/test-apt-ftparchive-cachedb | 24 |
2 files changed, 36 insertions, 21 deletions
diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index a5b889c15..3c5237915 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -242,34 +242,26 @@ bool FTWScanner::LoadFileList(string const &Dir, string const &File) if (List == 0) return _error->Errno("fopen",_("Failed to open %s"),File.c_str()); - /* We are a tad tricky here.. We prefix the buffer with the directory - name, that way if we need a full path with just use line.. Sneaky and - fully evil. */ - char Line[1000]; - char *FileStart; - if (Dir.empty() == true || Dir.end()[-1] != '/') - FileStart = Line + snprintf(Line,sizeof(Line),"%s/",Dir.c_str()); - else - FileStart = Line + snprintf(Line,sizeof(Line),"%s",Dir.c_str()); - while (fgets(FileStart,sizeof(Line) - (FileStart - Line),List) != 0) + std::string FilePathBuf; + char *Line = nullptr; + size_t LineLength = 0; + while (getline(&Line, &LineLength, List) != -1) { - char *FileName = _strstrip(FileStart); + const char *FileName = _strstrip(Line); if (FileName[0] == 0) continue; + // Relative path, prepend directory to make absolute if (FileName[0] != '/') { - if (FileName != FileStart) - memmove(FileStart,FileName,strlen(FileStart)); - FileName = Line; + if (Dir.empty() == true || Dir.end()[-1] != '/') + strprintf(FilePathBuf, "%s/%s", Dir.c_str(), FileName); + else + strprintf(FilePathBuf, "%s%s", Dir.c_str(), FileName); + + FileName = FilePathBuf.c_str(); } -#if 0 - struct stat St; - int Flag = FTW_F; - if (stat(FileName,&St) != 0) - Flag = FTW_NS; -#endif if (FileMatchesPatterns(FileName, Patterns) == false) continue; @@ -277,6 +269,7 @@ bool FTWScanner::LoadFileList(string const &Dir, string const &File) break; } + free(Line); fclose(List); return true; } diff --git a/test/integration/test-apt-ftparchive-cachedb b/test/integration/test-apt-ftparchive-cachedb index 1ba1f23ba..f6e71ccdb 100755 --- a/test/integration/test-apt-ftparchive-cachedb +++ b/test/integration/test-apt-ftparchive-cachedb @@ -69,6 +69,7 @@ Tree "dists/test" { Architectures "i386"; BinOverride "bin-override"; ExtraOverride "extra-override"; + //FileList "file-list"; }; EOF @@ -126,7 +127,6 @@ testsuccess $db_dump -f dump -p aptarchive-cache/packages-main-i386.db testsuccess grep "^ ./aptarchive/pool/main/foo_1_i386.deb:cl$" dump testsuccess grep "^ ./aptarchive/pool/main/foo_1_i386.deb:cn$" dump testsuccess grep "^ ./aptarchive/pool/main/foo_1_i386.deb:st$" dump - testsuccess aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1 # file is still found @@ -141,6 +141,28 @@ testsuccess grep "^ ./aptarchive/pool/main/${longPath}/foo_1_i386.deb:cl$" dump testsuccess grep "^ ./aptarchive/pool/main/${longPath}/foo_1_i386.deb:cn$" dump testsuccess grep "^ ./aptarchive/pool/main/${longPath}/foo_1_i386.deb:st"$ dump +msgmsg "Test file lists" + +# Check that the empty file list produces no packages +rm aptarchive-cache/packages-main-i386.db +testsuccess sed -i s#//FileList#FileList# ftparchive.conf +testsuccess aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1 +testfileequal ./aptarchive/dists/test/main/binary-i386/Packages "" + +# Add the packages and run our checks again +echo "pool/main/${longPath}/foo_1_i386.deb" > file-list +testsuccess aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1 +testsuccessequal "Filename: pool/main/${longPath}/foo_1_i386.deb" grep ^Filename ./aptarchive/dists/test/main/binary-i386/Packages +testsuccessequal "Priority: priority${manyX}" grep ^Priority ./aptarchive/dists/test/main/binary-i386/Packages +testsuccessequal "Section: overrideSection" grep ^Section ./aptarchive/dists/test/main/binary-i386/Packages +testsuccessequal "Extra: ${manyX}trailer" grep ^Extra ./aptarchive/dists/test/main/binary-i386/Packages + +# file is in the database +testsuccess $db_dump -f dump -p aptarchive-cache/packages-main-i386.db +testsuccess grep "^ ./aptarchive/pool/main/${longPath}/foo_1_i386.deb:cl$" dump +testsuccess grep "^ ./aptarchive/pool/main/${longPath}/foo_1_i386.deb:cn$" dump +testsuccess grep "^ ./aptarchive/pool/main/${longPath}/foo_1_i386.deb:st"$ dump + msgmsg "Test Clean" # and clean rm -rf aptarchive/pool/main/* |
