Skip to content

Commit

Permalink
Avoid using "~" in paths. Fixes issue #23.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Feb 27, 2013
1 parent 6e5fa03 commit 1a4fdd2
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions source/dub/packagemanager.d
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,17 @@ class PackageManager {
{
auto package_name = package_info.name.get!string();
auto package_version = package_info["version"].get!string();
auto clean_package_version = package_version[package_version.startsWith("~") ? 1 : 0 .. $];

logDebug("Installing package '%s' version '%s' to location '%s' from file '%s'",
package_name, package_version, to!string(location), zip_file_path.toNativeString());

logDebug("Installing package '%s' version '%s' to location '%s' from file '%s'",
package_name, package_version, to!string(location), zip_file_path.toNativeString());

Path destination;
final switch( location ){
case InstallLocation.local: destination = Path(package_name); break;
case InstallLocation.projectLocal: enforce(!m_projectPackagePath.empty, "no project path set."); destination = m_projectPackagePath ~ package_name; break;
case InstallLocation.userWide: destination = m_userPackagePath ~ (package_name ~ "/" ~ package_version); break;
case InstallLocation.systemWide: destination = m_systemPackagePath ~ (package_name ~ "/" ~ package_version); break;
case InstallLocation.userWide: destination = m_userPackagePath ~ (package_name ~ "/" ~ clean_package_version); break;
case InstallLocation.systemWide: destination = m_systemPackagePath ~ (package_name ~ "/" ~ clean_package_version); break;
}

if( existsFile(destination) ){
Expand All @@ -187,13 +188,13 @@ class PackageManager {
// open zip file
ZipArchive archive;
{
logTrace("Opening file %s", zip_file_path);
logTrace("Opening file %s", zip_file_path);
auto f = openFile(zip_file_path, FileMode.Read);
scope(exit) f.close();
archive = new ZipArchive(f.readAll());
}

logTrace("Installing from zip.");
logTrace("Installing from zip.");

// In a github zip, the actual contents are in a subfolder
Path zip_prefix;
Expand All @@ -211,7 +212,7 @@ class PackageManager {
zip_prefix = Path(am.name);
}

logTrace("zip root folder: %s", zip_prefix);
logTrace("zip root folder: %s", zip_prefix);

Path getCleanedPath(string fileName) {
auto path = Path(fileName);
Expand All @@ -222,14 +223,14 @@ class PackageManager {
// install
mkdirRecurse(destination.toNativeString());
auto journal = new Journal;
logDebug("Copying all files...");
int countFiles = 0;
logDebug("Copying all files...");
int countFiles = 0;
foreach(ArchiveMember a; archive.directory) {
auto cleanedPath = getCleanedPath(a.name);
if(cleanedPath.empty) continue;
auto dst_path = destination~cleanedPath;

logTrace("Creating %s", cleanedPath);
logTrace("Creating %s", cleanedPath);
if( dst_path.endsWithSlash ){
if( !existsDirectory(dst_path) )
mkdirRecurse(dst_path.toNativeString());
Expand All @@ -241,10 +242,10 @@ class PackageManager {
scope(exit) dstFile.close();
dstFile.put(archive.expand(a));
journal.add(Journal.Entry(Journal.Type.RegularFile, cleanedPath));
++countFiles;
++countFiles;
}
}
logDebug("%s file(s) copied.", to!string(countFiles));
logDebug("%s file(s) copied.", to!string(countFiles));

// overwrite package.json (this one includes a version field)
Json pi = jsonFromFile(destination~PackageJsonFilename);
Expand All @@ -260,14 +261,14 @@ class PackageManager {
logInfo("%s has been installed with version %s", package_name, package_version);

auto pack = new Package(location, destination);


final switch( location ){
case InstallLocation.local: break;
case InstallLocation.projectLocal: m_projectPackages[package_name] = pack; break;
case InstallLocation.userWide: m_userPackages[package_name] ~= pack; break;
case InstallLocation.systemWide: m_systemPackages[package_name] ~= pack; break;
}


return pack;
}

Expand Down

0 comments on commit 1a4fdd2

Please sign in to comment.