-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from emeraldpay/fix/double-slash
- Loading branch information
Showing
8 changed files
with
88 additions
and
46 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/io/emeraldpay/dshackle/archive/storage/BucketPath.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.emeraldpay.dshackle.archive.storage | ||
|
||
open class BucketPath( | ||
private val bucketPath: String, | ||
) { | ||
|
||
fun fullPathFor(path: String): String { | ||
return listOf(bucketPath, path) | ||
.filter { it != null && it.isNotEmpty() } | ||
.joinToString("/") | ||
.replace(Regex("//+"), "/") | ||
} | ||
|
||
fun forBlockchain(blockchainDir: String): BlockchainPath { | ||
return BlockchainPath(blockchainDir, this) | ||
} | ||
|
||
class BlockchainPath( | ||
private val blockchainDir: String, | ||
private val bucketPath: BucketPath, | ||
) { | ||
|
||
fun fullPathFor(path: String): String { | ||
return bucketPath.fullPathFor( | ||
listOf(blockchainDir, path).joinToString("/"), | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/test/groovy/io/emeraldpay/dshackle/archive/storage/BucketPathSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.emeraldpay.dshackle.archive.storage | ||
|
||
import spock.lang.Specification | ||
|
||
class BucketPathSpec extends Specification { | ||
|
||
def "Removes double slash"() { | ||
setup: | ||
def path = new BucketPath("a/b//") | ||
when: | ||
def result = path.fullPathFor("/c.txt") | ||
then: | ||
result == "a/b/c.txt" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters