Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions common/rsources.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,6 @@ bool SourcesList::ReadSources()
{
bool Res = true;

// Use config or fallback to /etc/apt/sources.list.d/
string Deb822Parts = _config->FindDir("Dir::Etc::sourcelist.d");
if (Deb822Parts.empty() || Deb822Parts == "/")
Deb822Parts = "/etc/apt/sources.list.d/";

if (FileExists(Deb822Parts) == true) {
Res &= ReadDeb822SourceDir(Deb822Parts);
}

// Then read Deb822 format sources from sourceparts as well
string Parts = _config->FindDir("Dir::Etc::sourceparts");
if (FileExists(Parts) == true) {
Res &= ReadDeb822SourceDir(Parts);
Expand Down
48 changes: 48 additions & 0 deletions tests/test_deb822_integration.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include <gtest/gtest.h>
#include "../common/rsources.h"
#include "../common/rsource_deb822.h"
#include <apt-pkg/configuration.h>
#include <apt-pkg/error.h>
#include <fstream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <sys/stat.h>
#include <unistd.h>

int main(int argc, char **argv) {
Expand Down Expand Up @@ -217,6 +220,51 @@ TEST_F(Deb822Test, SourcesListIntegration) {
remove(newFile.c_str());
}

TEST_F(Deb822Test, ReadSourcesDoesNotDuplicateDeb822SourceParts) {
char tmpdir[] = "/tmp/synaptic_sources_XXXXXX";
ASSERT_TRUE(mkdtemp(tmpdir) != NULL);

std::string sourceParts = std::string(tmpdir) + "/sources.list.d/";
ASSERT_EQ(mkdir(sourceParts.c_str(), 0700), 0);

std::string sourceFile = sourceParts + "debian.sources";
std::ofstream ofs(sourceFile.c_str());
ASSERT_TRUE(ofs.is_open());
ofs << "Types: deb\n"
<< "URIs: http://deb.debian.org/debian\n"
<< "Suites: trixie\n"
<< "Components: main\n\n";
ofs.close();

std::string oldSourceParts = _config->Find("Dir::Etc::sourceparts");
std::string oldSourceList = _config->Find("Dir::Etc::sourcelist");
std::string oldSourceListD = _config->Find("Dir::Etc::sourcelist.d");

_config->Set("Dir::Etc::sourceparts", sourceParts);
_config->Set("Dir::Etc::sourcelist", std::string(tmpdir) + "/missing.list");
_config->Set("Dir::Etc::sourcelist.d", sourceParts);

SourcesList sources;
ASSERT_TRUE(sources.ReadSources());

size_t deb822Records = 0;
for (std::list<SourcesList::SourceRecord *>::const_iterator it = sources.SourceRecords.begin();
it != sources.SourceRecords.end(); ++it) {
if ((*it)->Type & SourcesList::Deb822) {
deb822Records++;
}
}
EXPECT_EQ(deb822Records, 1u);

_config->Set("Dir::Etc::sourceparts", oldSourceParts);
_config->Set("Dir::Etc::sourcelist", oldSourceList);
_config->Set("Dir::Etc::sourcelist.d", oldSourceListD);

remove(sourceFile.c_str());
rmdir(sourceParts.c_str());
rmdir(tmpdir);
}

TEST_F(Deb822Test, ParseAdditionalFields) {
std::ofstream ofs(testFile.c_str());
ASSERT_TRUE(ofs.is_open());
Expand Down