Skip to content

Commit 0c03b46

Browse files
committed
Fix FileChannel#truncate not updating the last modified time
1 parent 4473d24 commit 0c03b46

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/java/org/codehaus/plexus/util/io/CachingOutputStream.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
import java.nio.Buffer;
2323
import java.nio.ByteBuffer;
2424
import java.nio.channels.FileChannel;
25+
import java.nio.file.Files;
2526
import java.nio.file.Path;
2627
import java.nio.file.StandardOpenOption;
28+
import java.nio.file.attribute.FileTime;
29+
import java.time.Instant;
2730
import java.util.Objects;
2831

2932
/**
@@ -154,7 +157,12 @@ public void close() throws IOException
154157
long position = channel.position();
155158
if ( position != channel.size() )
156159
{
157-
modified = true;
160+
if ( !modified )
161+
{
162+
FileTime now = FileTime.from( Instant.now() );
163+
Files.setLastModifiedTime( path, now );
164+
modified = true;
165+
}
158166
channel.truncate( position );
159167
}
160168
channel.close();

0 commit comments

Comments
 (0)