diff --git a/source/dub/dub.d b/source/dub/dub.d index c6f6a16..207426c 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -582,23 +582,19 @@ 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. diff --git a/test/issue674-concurrent-dub.sh b/test/issue674-concurrent-dub.sh index 984ad42..d1cfadd 100755 --- a/test/issue674-concurrent-dub.sh +++ b/test/issue674-concurrent-dub.sh @@ -11,6 +11,7 @@ cd ${TMPDIR} && $DUB fetch --cache=local bloom & pid1=$! +sleep 0.5 cd ${TMPDIR} && $DUB fetch --cache=local bloom & pid2=$! wait $pid1