Merge pull request #706 from MartinNowak/fixup_lock
better support concurrent fetch of package
commit ad411411354218580d34680361471ce03c6ae5e6
2 parents cdf2753 + e4cd8f5
@Sönke Ludwig Sönke Ludwig authored on 4 Oct 2015
Showing 2 changed files
View
23
source/dub/dub.d
if (!placement.existsFile())
mkdirRecurse(placement.toNativeString());
Path dstpath = placement ~ (packageId ~ "-" ~ clean_package_version);
 
if (auto lock = tryLockFile(dstpath.toNativeString() ~ ".lock")) // avoid concurrent fetch
auto lock = lockFile(dstpath.toNativeString() ~ ".lock", 30.seconds); // possibly wait for other dub instance
if (dstpath.existsFile())
{
auto path = getTempFile(packageId, ".zip");
supplier.retrievePackage(path, packageId, dep, (options & FetchOptions.usePrerelease) != 0); // Q: continue on fail?
scope(exit) std.file.remove(path.toNativeString());
 
logInfo("Placing %s %s to %s...", packageId, ver, placement.toNativeString());
 
return m_packageManager.storeFetchedPackage(path, pinfo, dstpath);
}
else
{
logInfo("Waiting for concurrent dub to fetch %s %s.", packageId, ver);
lockFile(dstpath.toNativeString() ~ ".lock", 30.seconds); // wait for other dub instance
m_packageManager.refresh(false);
return m_packageManager.getPackage(packageId, ver, dstpath);
}
 
auto path = getTempFile(packageId, ".zip");
supplier.retrievePackage(path, packageId, dep, (options & FetchOptions.usePrerelease) != 0); // Q: continue on fail?
scope(exit) std.file.remove(path.toNativeString());
 
logInfo("Placing %s %s to %s...", packageId, ver, placement.toNativeString());
return m_packageManager.storeFetchedPackage(path, pinfo, dstpath);
}
 
/// Removes a given package from the list of present/cached modules.
/// @removeFromApplication: if true, this will also remove an entry in the
View
1
■■■■
test/issue674-concurrent-dub.sh
trap cleanup EXIT
 
cd ${TMPDIR} && $DUB fetch --cache=local bloom &
pid1=$!
sleep 0.5
cd ${TMPDIR} && $DUB fetch --cache=local bloom &
pid2=$!
wait $pid1
wait $pid2