3131import org .apache .ratis .util .MemoizedSupplier ;
3232import org .apache .ratis .util .Preconditions ;
3333import org .apache .ratis .util .StringUtils ;
34+ import org .apache .ratis .util .function .CheckedFunction ;
3435import org .slf4j .Logger ;
3536import org .slf4j .LoggerFactory ;
3637
4344import java .nio .file .StandardOpenOption ;
4445import java .security .MessageDigest ;
4546import java .util .Optional ;
46- import java .util .function .Function ;
4747import java .util .function .Supplier ;
4848
4949/**
@@ -61,7 +61,7 @@ public class SnapshotManager {
6161
6262 private final Supplier <File > snapshotDir ;
6363 private final Supplier <File > snapshotTmpDir ;
64- private final Function <FileChunkProto , String > getRelativePath ;
64+ private final CheckedFunction <FileChunkProto , String , IOException > getRelativePath ;
6565 private MessageDigest digester ;
6666
6767 SnapshotManager (RaftPeerId selfId , Supplier <RaftStorageDirectory > dir , StateMachineStorage smStorage ) {
@@ -73,7 +73,7 @@ public class SnapshotManager {
7373
7474 final Supplier <Path > smDir = MemoizedSupplier .valueOf (() -> dir .get ().getStateMachineDir ().toPath ());
7575 this .getRelativePath = c -> smDir .get ().relativize (
76- new File (dir .get ().getRoot (), c .getFilename ()).toPath ()).toString ();
76+ FileUtils . resolveFullPath (dir .get ().getRoot (), c .getFilename ()).toPath ()).toString ();
7777 }
7878
7979 @ SuppressWarnings ({"squid:S2095" }) // Suppress closeable warning
@@ -121,7 +121,7 @@ public void installSnapshot(InstallSnapshotRequestProto request, StateMachine st
121121 + " with endIndex >= lastIncludedIndex " + lastIncludedIndex );
122122 }
123123
124- final File tmpSnapshotFile = new File (tmpDir , getRelativePath .apply (chunk ));
124+ final File tmpSnapshotFile = FileUtils . resolveFullPath (tmpDir , getRelativePath .apply (chunk ));
125125 FileUtils .createDirectoriesDeleteExistingNonDirectory (tmpSnapshotFile .getParentFile ());
126126
127127 try (FileChannel out = open (chunk , tmpSnapshotFile )) {
@@ -180,8 +180,8 @@ private static void rename(File tmpDir, File stateMachineDir) throws IOException
180180 try {
181181 moved = FileUtils .move (stateMachineDir , TMP + StringUtils .currentDateTime ());
182182 } catch (IOException e ) {
183- LOG .warn ("Failed to rename state machine directory " + stateMachineDir . getAbsolutePath ()
184- + " to a " + TMP + " directory. Try deleting it directly." , e );
183+ LOG .warn ("Failed to rename state machine directory {} to a {} directory. Try deleting it directly." ,
184+ TMP , stateMachineDir . getAbsolutePath () , e );
185185 FileUtils .deleteFully (stateMachineDir );
186186 }
187187 existingDir = moved ;
0 commit comments