#119 Better feedback for dub add-local, dub remove-local
1 parent 1f57ce8 commit f2223ae766e696ef95ab7678a2cb3e6f32139ac8
@Matthias Dondorff Matthias Dondorff authored on 18 Sep 2013
Showing 1 changed file
View
20
source/dub/packagemanager.d
// don't double-add packages
foreach( p; *packs ){
if( p.path == path ){
enforce(p.ver == ver, "Adding local twice with different versions is not allowed.");
logInfo("Package is already registered: %s (version: %s)", p.name, p.ver);
return p;
}
}
 
*packs ~= pack;
 
writeLocalPackageList(type);
 
logInfo("Registered package: %s (version: %s)", pack.name, pack.ver);
return pack;
}
 
void removeLocalPackage(in Path path, LocalPackageType type)
if( entry.path == path )
to_remove ~= i;
enforce(to_remove.length > 0, "No "~type.to!string()~" package found at "~path.toNativeString());
 
foreach_reverse( i; to_remove )
string[Version] removed;
foreach_reverse( i; to_remove ) {
removed[(*packs)[i].ver] = (*packs)[i].name;
*packs = (*packs)[0 .. i] ~ (*packs)[i+1 .. $];
}
 
writeLocalPackageList(type);
 
foreach(ver, name; removed)
logInfo("Unregistered package: %s (version: %s)", name, ver);
}
 
Package getTemporaryPackage(Path path, Version ver)
{
Path list_path = m_repositories[type].packagePath;
Package[] packs;
Path[] paths;
try {
logDiagnostic("Looking for local package map at %s", list_path.toNativeString());
if( !existsFile(list_path ~ LocalPackagesFilename) ) return;
logDiagnostic("Try to load local package map at %s", list_path.toNativeString());
auto local_package_file = list_path ~ LocalPackagesFilename;
logDiagnostic("Looking for local package map at %s", local_package_file.toNativeString());
if( !existsFile(local_package_file) ) return;
logDiagnostic("Try to load local package map at %s", local_package_file.toNativeString());
auto packlist = jsonFromFile(list_path ~ LocalPackagesFilename);
enforce(packlist.type == Json.Type.Array, LocalPackagesFilename~" must contain an array.");
foreach( pentry; packlist ){
try {