@@ -583,27 +583,71 @@ class PackageManager {
583
583
throw new Exception (format(" No override exists for %s %s" , package_, src));
584
584
}
585
585
586
- // / Extracts the package supplied as a path to it's zip file to the
587
- // / destination and sets a version field in the package description.
586
+ deprecated (" Use `store(NativePath source, PlacementLocation dest, string name, Version vers)`" )
588
587
Package storeFetchedPackage (NativePath zip_file_path, Json package_info, NativePath destination)
589
588
{
590
- import std.range : walkLength;
589
+ return this .store_(zip_file_path, destination, package_info[" name" ].get ! string ,
590
+ Version(package_info[" version" ].get ! string ));
591
+ }
591
592
592
- auto package_name = package_info[" name" ].get ! string ;
593
- auto package_version = package_info[" version" ].get ! string ;
593
+ /**
594
+ * Store a zip file stored at `src` into a managed location `destination`
595
+ *
596
+ * This will extracts the package supplied as (as a zip file) to the
597
+ * `destination` and sets a version field in the package description.
598
+ * In the future, we should aim not to alter the package description,
599
+ * but this is done for backward compatibility.
600
+ *
601
+ * Params:
602
+ * src = The path to the zip file containing the package
603
+ * dest = At which `PlacementLocation` the package should be stored
604
+ * name = Name of the package being stored
605
+ * vers = Version of the package
606
+ *
607
+ * Returns:
608
+ * The `Package` after it has been loaded.
609
+ *
610
+ * Throws:
611
+ * If the package cannot be loaded / the zip is corrupted / the package
612
+ * already exists, etc...
613
+ */
614
+ Package store (NativePath src, PlacementLocation dest, string name, Version vers)
615
+ {
616
+ NativePath dstpath = this .getPackagePath(dest, name, vers.toString());
617
+ if (! dstpath.existsFile())
618
+ mkdirRecurse(dstpath.toNativeString());
619
+ // For libraries leaking their import path
620
+ dstpath = dstpath ~ name;
621
+
622
+ // possibly wait for other dub instance
623
+ import core.time : seconds;
624
+ auto lock = lockFile(dstpath.toNativeString() ~ " .lock" , 30. seconds);
625
+ if (dstpath.existsFile()) {
626
+ this .refresh(false );
627
+ return this .getPackage(name, vers, dest);
628
+ }
629
+ return this .store_(src, dstpath, name, vers);
630
+ }
631
+
632
+ // / Backward-compatibility for deprecated overload, simplify once `storeFetchedPatch`
633
+ // / is removed
634
+ private Package store_ (NativePath src, NativePath destination, string name, Version vers)
635
+ {
636
+ import std.range : walkLength;
594
637
595
638
logDebug(" Placing package '%s' version '%s' to location '%s' from file '%s'" ,
596
- package_name, package_version , destination.toNativeString(), zip_file_path .toNativeString());
639
+ name, vers , destination.toNativeString(), src .toNativeString());
597
640
598
641
if ( existsFile(destination) ){
599
- throw new Exception (format(" %s (%s) needs to be removed from '%s' prior placement." , package_name, package_version, destination));
642
+ throw new Exception (format(" %s (%s) needs to be removed from '%s' prior placement." ,
643
+ name, vers, destination));
600
644
}
601
645
602
646
// open zip file
603
647
ZipArchive archive;
604
648
{
605
- logDebug(" Opening file %s" , zip_file_path );
606
- auto f = openFile(zip_file_path , FileMode.read);
649
+ logDebug(" Opening file %s" , src );
650
+ auto f = openFile(src , FileMode.read);
607
651
scope (exit) f.close();
608
652
archive = new ZipArchive (f.readAll());
609
653
}
@@ -669,7 +713,7 @@ class PackageManager {
669
713
logDebug(" %s file(s) copied." , to! string (countFiles));
670
714
671
715
// overwrite dub.json (this one includes a version field)
672
- auto pack = Package.load(destination, NativePath.init, null , package_info[ " version " ]. get ! string );
716
+ auto pack = Package.load(destination, NativePath.init, null , vers.toString() );
673
717
674
718
if (pack.recipePath.head != defaultPackageFilename)
675
719
// Storeinfo saved a default file, this could be different to the file from the zip.
0 commit comments