Skip to content

Commit 4cfbe7c

Browse files
authored
Update getS3Key to avoid filename conflict (#112)
1 parent b20a29b commit 4cfbe7c

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

storage/src/main/java/org/commonjava/storage/pathmapped/core/S3PhysicalStore.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.OutputStream;
3030
import java.nio.file.Paths;
3131

32+
import static java.lang.System.currentTimeMillis;
3233
import static org.commonjava.storage.pathmapped.util.PathMapUtils.getRandomFileId;
3334

3435
public class S3PhysicalStore implements PhysicalStore
@@ -55,13 +56,17 @@ public FileInfo getFileInfo( String fileSystem, String path )
5556
}
5657

5758
/**
58-
* Some characters that might require special handling, like Colon ':'. This default impl is replacing colon
59-
* with slash '/'. Derived classes can override the default behavior.
59+
* Some characters that might require special handling, like Colon ':'. This default impl replaces colon
60+
* with slash '/' and appends a timestamp to path to avoid conflict. (e.g, if a file is deleted and put again,
61+
* the new physical file can be removed by GC after the grace period if the 'storagefile' are same).
62+
* The timestamp uses the last 5 digital of current-time-millis.
6063
* @return valid S3 key string
6164
*/
6265
protected String getS3Key( String filesystem, String path )
6366
{
64-
return Paths.get( filesystem.replaceAll(":", "/"), path ).toString();
67+
String tmp = Long.toString( currentTimeMillis() );
68+
String timestamp = tmp.substring( tmp.length() - 5 );
69+
return Paths.get( filesystem.replaceAll(":", "/"), path + "." + timestamp ).toString();
6570
}
6671

6772
@Override

0 commit comments

Comments
 (0)