Skip to content

Commit

Permalink
#22 - fixed qulice issues
Browse files Browse the repository at this point in the history
  • Loading branch information
g4s8 committed Feb 28, 2020
1 parent df81041 commit 7ad0bc1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
39 changes: 33 additions & 6 deletions src/main/java/com/artipie/rpm/NamingPolicy.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Yegor Bugayenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.artipie.rpm;

import hu.akarnokd.rxjava2.interop.SingleInterop;
Expand Down Expand Up @@ -46,7 +69,7 @@ final class Sha1Prefixed implements NamingPolicy {
* Default ctor.
*/
public Sha1Prefixed() {
this(Sha1Prefixed::sha1Digest);
this(Sha1Prefixed::shaOneDigest);
}

/**
Expand All @@ -62,10 +85,14 @@ public CompletionStage<String> name(
final String source, final Publisher<ByteBuffer> content
) {
return Flowable.fromPublisher(content)
.reduce(this.dgst.get(), (acc, buf) -> {
acc.update(buf);
return acc;
}).map(res -> new HexOf(new BytesOf(res.digest())).asString())
.reduce(
this.dgst.get(),
(acc, buf) -> {
acc.update(buf);
return acc;
}
)
.map(res -> new HexOf(new BytesOf(res.digest())).asString())
.map(hex -> String.format("%s-%s", hex, source))
.to(SingleInterop.get());
}
Expand All @@ -74,7 +101,7 @@ public CompletionStage<String> name(
* SHA1 message digest.
* @return Digest
*/
private static MessageDigest sha1Digest() {
private static MessageDigest shaOneDigest() {
try {
return MessageDigest.getInstance("SHA1");
} catch (final NoSuchAlgorithmException err) {
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/artipie/rpm/Repomd.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ final class Repomd {
* Ctor.
*
* @param stg The storage
* @param naming
* @param naming Naming policy
*/
Repomd(final Storage stg, final NamingPolicy naming) {
this.storage = stg;
Expand Down Expand Up @@ -147,8 +147,9 @@ private CompletableSource performUpdate(
);
}
final Path gzip = Files.createTempFile("x", ".gz");
return res.andThen(SingleInterop.fromFuture(this.naming.name(type, new RxFile(file).flow())))
.map(target -> String.format("repodata/%s.xml", target))
return res.andThen(
SingleInterop.fromFuture(this.naming.name(type, new RxFile(file).flow()))
).map(target -> String.format("repodata/%s.xml", target))
.flatMapCompletable(
key -> act.update(file)
.andThen(Repomd.gzip(file, gzip))
Expand Down Expand Up @@ -240,8 +241,8 @@ private static Completable gzip(final Path input, final Path output) {
return Completable.fromAction(
() -> {
try (InputStream fis = Files.newInputStream(input);
OutputStream fos = Files.newOutputStream(output);
GZIPOutputStream gzos = new GZIPOutputStream(fos)) {
OutputStream fos = Files.newOutputStream(output);
GZIPOutputStream gzos = new GZIPOutputStream(fos)) {
// @checkstyle MagicNumberCheck (1 line)
final byte[] buffer = new byte[65_536];
while (true) {
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/com/artipie/rpm/RpmITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
Expand Down Expand Up @@ -168,7 +167,6 @@ public void primaryFileIsTheSameAsCreateRepoGenerates() throws Exception {
rpm.update(key).blockingAwait();
final String expected = this.etalon(bin);
final String actual = primary(repo);
System.out.printf("EXPECTED:\n\n%s\n\nACTUAL:\n\n%s\n", expected, actual);
comparePrimaryFiles(expected, actual);
}

Expand Down

0 comments on commit 7ad0bc1

Please sign in to comment.