@@ -63,7 +63,7 @@ std::vector<StartupAction> startup_actions{
6363 { 7 , StartupAction::ClearStorageDirExp | StartupAction::ClearStorageDirBin | StartupAction::ClearStorageDirLib },
6464 { 8 , StartupAction::ClearCfgDirs },
6565 { 9 , StartupAction::ClearStorageDirExp },
66- // 10
66+ { 10 , StartupAction::ClearPackagesDatabase },
6767};
6868
6969const TableDescriptors &get_service_tables ()
@@ -211,7 +211,7 @@ const TableDescriptors data_tables{
211211 "branch" TEXT,
212212 "flags" INTEGER NOT NULL,
213213 "created" DATE NOT NULL,
214- "sha256 " TEXT NOT NULL,
214+ "hash " TEXT NOT NULL,
215215 PRIMARY KEY ("id"),
216216 FOREIGN KEY ("project_id") REFERENCES "Projects" ("id")
217217 );
@@ -477,6 +477,11 @@ void ServiceDatabase::performStartupActions() const
477477 }
478478 }
479479
480+ if (a.action & StartupAction::ClearPackagesDatabase)
481+ {
482+ fs::remove (getDbDirectory () / packages_db_name);
483+ }
484+
480485 if (a.action & StartupAction::ClearStorageDirExp)
481486 {
482487 remove_all_from_dir (directories.storage_dir_exp );
@@ -1076,7 +1081,7 @@ IdDependencies PackagesDatabase::findDependencies(const Packages &deps) const
10761081 auto find_deps = [&dep, &all_deps, this ](auto &dependency)
10771082 {
10781083 dependency.flags .set (pfDirectDependency);
1079- dependency.id = getExactProjectVersionId (dependency, dependency.version , dependency.flags , dependency.sha256 );
1084+ dependency.id = getExactProjectVersionId (dependency, dependency.version , dependency.flags , dependency.hash );
10801085 all_deps[dependency] = dependency; // assign first, deps assign second
10811086 all_deps[dependency].db_dependencies = getProjectDependencies (dependency.id , all_deps);
10821087 };
@@ -1136,7 +1141,7 @@ void check_version_age(const TimePoint &t1, const char *created)
11361141 throw std::runtime_error (" One of the queried packages is 'young'. Young packages must be retrieved from server." );
11371142}
11381143
1139- ProjectVersionId PackagesDatabase::getExactProjectVersionId (const DownloadDependency &project, Version &version, ProjectFlags &flags, String &sha256 ) const
1144+ ProjectVersionId PackagesDatabase::getExactProjectVersionId (const DownloadDependency &project, Version &version, ProjectFlags &flags, String &hash ) const
11401145{
11411146 auto err = [](const auto &v, const auto &p)
11421147 {
@@ -1148,7 +1153,7 @@ ProjectVersionId PackagesDatabase::getExactProjectVersionId(const DownloadDepend
11481153 static auto tstart = getUtc ();
11491154
11501155 ProjectVersionId id = 0 ;
1151- static const String select = " select id, major, minor, patch, flags, sha256 , created from ProjectVersions where " ;
1156+ static const String select = " select id, major, minor, patch, flags, hash , created from ProjectVersions where " ;
11521157
11531158 if (!version.isBranch ())
11541159 {
@@ -1159,11 +1164,11 @@ ProjectVersionId PackagesDatabase::getExactProjectVersionId(const DownloadDepend
11591164 " project_id = '" + std::to_string (project.id ) + " ' and "
11601165 " major = '" + std::to_string (v.major ) + " ' and "
11611166 " minor = '" + std::to_string (v.minor ) + " ' and "
1162- " patch = '" + std::to_string (v.patch ) + " '" , [&id, &flags, &sha256 ](SQLITE_CALLBACK_ARGS)
1167+ " patch = '" + std::to_string (v.patch ) + " '" , [&id, &flags, &hash ](SQLITE_CALLBACK_ARGS)
11631168 {
11641169 id = std::stoull (cols[0 ]);
11651170 flags |= decltype (project.flags )(std::stoull (cols[4 ]));
1166- sha256 = cols[5 ];
1171+ hash = cols[5 ];
11671172 check_version_age (tstart, cols[6 ]);
11681173 return 0 ;
11691174 });
@@ -1179,12 +1184,12 @@ ProjectVersionId PackagesDatabase::getExactProjectVersionId(const DownloadDepend
11791184 " major = '" + std::to_string (v.major ) + " ' and "
11801185 " minor = '" + std::to_string (v.minor ) + " ' and "
11811186 " branch is null order by major desc, minor desc, patch desc limit 1" ,
1182- [&id, &version, &flags, &sha256 ](SQLITE_CALLBACK_ARGS)
1187+ [&id, &version, &flags, &hash ](SQLITE_CALLBACK_ARGS)
11831188 {
11841189 id = std::stoull (cols[0 ]);
11851190 version.patch = std::stoi (cols[3 ]);
11861191 flags |= decltype (project.flags )(std::stoull (cols[4 ]));
1187- sha256 = cols[5 ];
1192+ hash = cols[5 ];
11881193 check_version_age (tstart, cols[6 ]);
11891194 return 0 ;
11901195 });
@@ -1199,13 +1204,13 @@ ProjectVersionId PackagesDatabase::getExactProjectVersionId(const DownloadDepend
11991204 " project_id = '" + std::to_string (project.id ) + " ' and "
12001205 " major = '" + std::to_string (v.major ) + " ' and "
12011206 " branch is null order by major desc, minor desc, patch desc limit 1" ,
1202- [&id, &version, &flags, &sha256 ](SQLITE_CALLBACK_ARGS)
1207+ [&id, &version, &flags, &hash ](SQLITE_CALLBACK_ARGS)
12031208 {
12041209 id = std::stoull (cols[0 ]);
12051210 version.minor = std::stoi (cols[2 ]);
12061211 version.patch = std::stoi (cols[3 ]);
12071212 flags |= decltype (project.flags )(std::stoull (cols[4 ]));
1208- sha256 = cols[5 ];
1213+ hash = cols[5 ];
12091214 check_version_age (tstart, cols[6 ]);
12101215 return 0 ;
12111216 });
@@ -1219,14 +1224,14 @@ ProjectVersionId PackagesDatabase::getExactProjectVersionId(const DownloadDepend
12191224 select + " "
12201225 " project_id = '" + std::to_string (project.id ) + " ' and "
12211226 " branch is null order by major desc, minor desc, patch desc limit 1" ,
1222- [&id, &version, &flags, &sha256 ](SQLITE_CALLBACK_ARGS)
1227+ [&id, &version, &flags, &hash ](SQLITE_CALLBACK_ARGS)
12231228 {
12241229 id = std::stoull (cols[0 ]);
12251230 version.major = std::stoi (cols[1 ]);
12261231 version.minor = std::stoi (cols[2 ]);
12271232 version.patch = std::stoi (cols[3 ]);
12281233 flags |= decltype (project.flags )(std::stoull (cols[4 ]));
1229- sha256 = cols[5 ];
1234+ hash = cols[5 ];
12301235 check_version_age (tstart, cols[6 ]);
12311236 return 0 ;
12321237 });
@@ -1245,11 +1250,11 @@ ProjectVersionId PackagesDatabase::getExactProjectVersionId(const DownloadDepend
12451250 db->execute (
12461251 select + " "
12471252 " project_id = '" + std::to_string (project.id ) + " ' and "
1248- " branch = '" + version.toString () + " '" , [&id, &flags, &sha256 ](SQLITE_CALLBACK_ARGS)
1253+ " branch = '" + version.toString () + " '" , [&id, &flags, &hash ](SQLITE_CALLBACK_ARGS)
12491254 {
12501255 id = std::stoull (cols[0 ]);
12511256 flags |= decltype (project.flags )(std::stoull (cols[4 ]));
1252- sha256 = cols[5 ];
1257+ hash = cols[5 ];
12531258 check_version_age (tstart, cols[6 ]);
12541259 return 0 ;
12551260 });
@@ -1288,7 +1293,7 @@ PackagesDatabase::Dependencies PackagesDatabase::getProjectDependencies(ProjectV
12881293
12891294 for (auto &dependency : deps)
12901295 {
1291- dependency.id = getExactProjectVersionId (dependency, dependency.version , dependency.flags , dependency.sha256 );
1296+ dependency.id = getExactProjectVersionId (dependency, dependency.version , dependency.flags , dependency.hash );
12921297 auto i = dm.find (dependency);
12931298 if (i == dm.end ())
12941299 {
0 commit comments