]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/rpmfactory/CreateSrpm.java
Add distribution cache in CreateSrpm
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / lib / linux / rpmfactory / CreateSrpm.java
index e48df91433127d8921c98348b24aadf81be7c8a1..aa19a8342e5f568be84f311b5428a34293e51ba3 100644 (file)
@@ -22,6 +22,9 @@ public class CreateSrpm implements Runnable {
 
        private File topdir;
 
+       /** Directory where to cache downloaded dsitributions. */
+       private File distributionCache;
+
        private Resource specFile;
 
        private RpmBuildEnvironment rpmBuildEnvironment;
@@ -114,11 +117,25 @@ public class CreateSrpm implements Runnable {
 
                        // FIXME: we may have missed some files here
                        copySources: for (Resource res : toCopyToSources) {
-                               File targetFile = new File(sourcesDir, res.getFilename())
+                               File targetDir;
+                               if (distributionCache != null) {
+                                       if (distributionCache.exists())
+                                               distributionCache.mkdirs();
+                                       targetDir = distributionCache;
+                               } else
+                                       targetDir = sourcesDir;
+                               File targetFile = new File(targetDir, res.getFilename())
                                                .getCanonicalFile();
-                               if (targetFile.exists() && !overwriteSources)
-                                       continue copySources;
-                               copyResourceToFile(res, targetFile);
+                               if (!targetFile.exists() || overwriteSources)
+                                       copyResourceToFile(res, targetFile);
+                               if (!targetDir.equals(sourcesDir)) {
+                                       File fileInSourcesDir = new File(sourcesDir, targetFile
+                                                       .getName());
+                                       if (!fileInSourcesDir.exists()
+                                                       || !(fileInSourcesDir.length() == targetFile
+                                                                       .length()))
+                                               FileUtils.copyFile(targetFile, fileInSourcesDir);
+                               }
                        }
                } catch (Exception e) {
                        throw new SlcException("Cannot copy to " + sourcesDir, e);
@@ -175,4 +192,8 @@ public class CreateSrpm implements Runnable {
                this.rpmBuildEnvironment = rpmBuildEnvironment;
        }
 
+       public void setDistributionCache(File distributionCache) {
+               this.distributionCache = distributionCache;
+       }
+
 }