mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-10-28 20:15:22 +00:00
[JENKINS-52325] - If copy of artifact with attributes throws error, retry without attributes (#3537)
[JENKINS-52325] - If copy of artifact with attributes throws error, retry without attributes
This commit is contained in:
1 parent
319ce84a5e
commit
af6dc33ff4
1 file changed
+26
-2
@@ -58,6 +58,9 @@ import hudson.util.IOUtils;
|
||||
import hudson.util.NamingThreadFactory;
|
||||
import hudson.util.io.Archiver;
|
||||
import hudson.util.io.ArchiverFactory;
|
||||
|
||||
import static java.util.logging.Level.FINE;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
@@ -2457,16 +2460,37 @@ public final class FilePath implements Serializable {
|
||||
final File dest = new File(target.remote);
|
||||
final AtomicInteger count = new AtomicInteger();
|
||||
scanner.scan(base, reading(new FileVisitor() {
|
||||
private boolean exceptionEncountered;
|
||||
private boolean logMessageShown;
|
||||
@Override
|
||||
public void visit(File f, String relativePath) throws IOException {
|
||||
if (f.isFile()) {
|
||||
File target = new File(dest, relativePath);
|
||||
mkdirsE(target.getParentFile());
|
||||
Files.copy(fileToPath(f), fileToPath(writing(target)),
|
||||
StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
|
||||
Path targetPath = fileToPath(writing(target));
|
||||
exceptionEncountered = exceptionEncountered || !tryCopyWithAttributes(f, targetPath);
|
||||
if (exceptionEncountered) {
|
||||
Files.copy(fileToPath(f), targetPath, StandardCopyOption.REPLACE_EXISTING);
|
||||
if (!logMessageShown) {
|
||||
LOGGER.log(Level.INFO,
|
||||
"JENKINS-52325: Jenkins failed to retain attributes when copying to {0}, so proceeding without attributes.",
|
||||
dest.getAbsolutePath());
|
||||
logMessageShown = true;
|
||||
}
|
||||
}
|
||||
count.incrementAndGet();
|
||||
}
|
||||
}
|
||||
private boolean tryCopyWithAttributes(File f, Path targetPath) {
|
||||
try {
|
||||
Files.copy(fileToPath(f), targetPath,
|
||||
StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
|
||||
} catch (IOException e) {
|
||||
LOGGER.log(Level.FINE, "Unable to copy: {0}", e.getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean understandsSymlink() {
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user