[ https://issues.apache.org/jira/browse/MRESOLVER-536?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17837685#comment-17837685 ]
ASF GitHub Bot commented on MRESOLVER-536: ------------------------------------------ cstamas commented on code in PR #471: URL: https://github.com/apache/maven-resolver/pull/471#discussion_r1567225174 ########## maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultPathProcessor.java: ########## @@ -21,22 +21,47 @@ import javax.inject.Named; import javax.inject.Singleton; -import java.io.*; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; +import java.nio.file.AccessDeniedException; +import java.nio.file.FileSystemException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; +import java.nio.file.attribute.FileTime; import org.eclipse.aether.spi.io.PathProcessor; import org.eclipse.aether.util.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A utility class helping with file-based operations. */ @Singleton @Named public class DefaultPathProcessor implements PathProcessor { + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @Override + public void setLastModified(Path path, long value) throws IOException { + try { + Files.setLastModifiedTime(path, FileTime.fromMillis(value)); + } catch (FileSystemException e) { + // MRESOLVER-536: Java uses generic FileSystemException for some weird cases, + // but some subclasses like AccessDeniedEx should be re-thrown + if (e instanceof AccessDeniedException) { + throw e; + } + logger.debug("Failed to set last-modified: {}", path, e); Review Comment: fixed ########## maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultPathProcessor.java: ########## @@ -21,22 +21,47 @@ import javax.inject.Named; import javax.inject.Singleton; -import java.io.*; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; +import java.nio.file.AccessDeniedException; +import java.nio.file.FileSystemException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; +import java.nio.file.attribute.FileTime; import org.eclipse.aether.spi.io.PathProcessor; import org.eclipse.aether.util.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A utility class helping with file-based operations. */ @Singleton @Named public class DefaultPathProcessor implements PathProcessor { + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @Override + public void setLastModified(Path path, long value) throws IOException { + try { + Files.setLastModifiedTime(path, FileTime.fromMillis(value)); + } catch (FileSystemException e) { + // MRESOLVER-536: Java uses generic FileSystemException for some weird cases, + // but some subclasses like AccessDeniedEx should be re-thrown + if (e instanceof AccessDeniedException) { + throw e; + } + logger.debug("Failed to set last-modified: {}", path, e); Review Comment: fixed > Skip setting last modified time when FS does not support it > ----------------------------------------------------------- > > Key: MRESOLVER-536 > URL: https://issues.apache.org/jira/browse/MRESOLVER-536 > Project: Maven Resolver > Issue Type: Improvement > Components: Resolver > Affects Versions: 1.9.18 > Reporter: Jurrie Overgoor > Assignee: Tamas Cservenak > Priority: Major > Fix For: 2.0.0, 1.9.19, 2.0.0-alpha-11 > > Attachments: Stacktrace.txt > > > When Maven resolver downloads a file and writes it to disk, it tries to set > the last modified time on it. There are filesystems that do not support the > "set last modified time" operation. In that case the operation will fail, and > the Maven build will error out with a {{FileSystemException}}. Attached is > (the last part of) such a stack track trace. > I encountered such a file system when running in a Kubernetes (Openshift > actually, but that's Kubernetes based) cloud setup. I mapped the {{~/.m2}} > directory to a Persistent Volume Claim so that files downloaded in one build > are retained in the next build. I explicitly set the access mode to > ReadWriteMany (a.k.a. RWX, a.k.a. Shared Access) so that multiple build nodes > can use the same PVC. The PVC is provisioned by a [`file.csi.azure.com` > provisioner|https://learn.microsoft.com/en-us/azure/aks/azure-files-csi]. And > that translates to a file system that does not support setting the last > modified time on a file. Thus the call to > {{java.nio.file.Files.setLastModifiedTime(Path, FileTime)}} in > {{org.eclipse.aether.transport.http.HttpTransporter.EntityGetter.handle(CloseableHttpResponse)org.eclipse.aether.transport.http.HttpTransporter.EntityGetter.handle(CloseableHttpResponse)}} > comes crashing down. > There is no good way to query if the FS supports the call. So I resorted to > wrapping the call in a `try .. catch` block. This seems to work. Maven > downloads dependencies again, and my build progresses. -- This message was sent by Atlassian Jira (v8.20.10#820010)