diff --git a/source/dub/dub.d b/source/dub/dub.d index c5f0909..bf1bef9 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -159,7 +159,7 @@ ps ~= defaultPackageSuppliers(); m_packageSuppliers = ps; - m_packageManager = new PackageManager(m_dirs.userSettings, m_dirs.systemSettings); + m_packageManager = new PackageManager(m_dirs.localRepository, m_dirs.systemSettings); updatePackageSearchPath(); } @@ -198,12 +198,18 @@ import std.file : tempDir; version(Windows) { m_dirs.systemSettings = NativePath(environment.get("ProgramData")) ~ "dub/"; - m_dirs.userSettings = NativePath(environment.get("APPDATA")) ~ "dub/"; + immutable appDataDir = environment.get("APPDATA"); + m_dirs.userSettings = NativePath(appDataDir) ~ "dub/"; + m_dirs.localRepository = NativePath(environment.get("LOCALAPPDATA", appDataDir)) ~ "dub"; + + migrateRepositoryFromRoaming(m_dirs.userSettings ~"\\packages", m_dirs.localRepository ~ "\\packages"); + } else version(Posix){ m_dirs.systemSettings = NativePath("/var/lib/dub/"); m_dirs.userSettings = NativePath(environment.get("HOME")) ~ ".dub/"; if (!m_dirs.userSettings.absolute) m_dirs.userSettings = NativePath(getcwd()) ~ m_dirs.userSettings; + m_dirs.localRepository = m_dirs.userSettings; } m_dirs.temp = NativePath(tempDir); @@ -215,6 +221,24 @@ determineDefaultCompiler(); } + version(Windows) + private void migrateRepositoryFromRoaming(NativePath roamingDir, NativePath localDir) + { + immutable roamingDirPath = roamingDir.toNativeString(); + if (!existsDirectory(roamingDir)) return; + + immutable localDirPath = localDir.toNativeString(); + logInfo("Detected a package cache in " ~ roamingDirPath ~ ". This will be migrated to " ~ localDirPath ~ ". Please wait..."); + if (!existsDirectory(localDir)) + { + mkdirRecurse(localDirPath); + } + + runCommand("xcopy /s /e /y " ~ roamingDirPath ~ " " ~ localDirPath ~ " > NUL"); + rmdirRecurse(roamingDirPath); + } + + @property void dryRun(bool v) { m_dryRun = v; } /** Returns the root path (usually the current working directory). @@ -699,7 +723,7 @@ NativePath placement; final switch (location) { case PlacementLocation.local: placement = m_rootPath; break; - case PlacementLocation.user: placement = m_dirs.userSettings ~ "packages/"; break; + case PlacementLocation.user: placement = m_dirs.localRepository ~ "packages/"; break; case PlacementLocation.system: placement = m_dirs.systemSettings ~ "packages/"; break; } @@ -1554,6 +1578,7 @@ NativePath temp; NativePath userSettings; NativePath systemSettings; + NativePath localRepository; } private class DubConfig {