Skip to content

Commit

Permalink
qulice warn fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammers21 committed Jan 14, 2020
1 parent 7e094f6 commit bc789b6
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 55 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/yegor256/rpm/Checksum.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ final class Checksum {
public Single<String> sha() {
return Single.fromCallable(
() -> Files.readAllBytes(this.file)
).map(bytes -> DatatypeConverter.printHexBinary(
MessageDigest.getInstance("SHA-256").digest(bytes)
).toLowerCase(Locale.ENGLISH));
).map(
bytes -> DatatypeConverter.printHexBinary(
MessageDigest.getInstance("SHA-256").digest(bytes)
).toLowerCase(Locale.ENGLISH));
}

}
4 changes: 1 addition & 3 deletions src/main/java/com/yegor256/rpm/Other.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
*/
package com.yegor256.rpm;

import java.io.IOException;
import java.nio.file.Path;

import io.reactivex.rxjava3.core.Completable;
import java.nio.file.Path;
import org.redline_rpm.header.Header;
import org.xembly.Directives;

Expand Down
61 changes: 32 additions & 29 deletions src/main/java/com/yegor256/rpm/Primary.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public Completable update(final String key, final Pkg pkg) {
.set(checksum)
.up()
)
.map(directives ->
.map(
directives ->
directives
.add("summary")
.set(pkg.tag(Header.HeaderTag.SUMMARY))
Expand Down Expand Up @@ -132,34 +133,36 @@ public Completable update(final String key, final Pkg pkg) {
.attr("archive", pkg.num(Header.HeaderTag.ARCHIVESIZE))
.up()
)
.map(directives -> directives
.add("location")
.attr("href", key)
.up()
.add("format")
.add("rpm:license")
.set(pkg.tag(Header.HeaderTag.LICENSE))
.up()
.add("rpm:vendor")
.set(pkg.tag(Header.HeaderTag.VENDOR))
.up()
.add("rpm:group")
.set(pkg.tag(Header.HeaderTag.GROUP))
.up()
.add("rpm:buildhost")
.set(pkg.tag(Header.HeaderTag.BUILDHOST))
.up()
.add("rpm:sourcerpm")
.set(pkg.tag(Header.HeaderTag.SOURCERPM))
.up()
.add("rpm:header-range")
.attr("start", pkg.header().getStartPos())
.attr("end", pkg.header().getEndPos())
.up()
.append(rpmProvides(pkg))
.append(rpmRequires(pkg))
.append(files(pkg))
.up()
.map(
directives ->
directives
.add("location")
.attr("href", key)
.up()
.add("format")
.add("rpm:license")
.set(pkg.tag(Header.HeaderTag.LICENSE))
.up()
.add("rpm:vendor")
.set(pkg.tag(Header.HeaderTag.VENDOR))
.up()
.add("rpm:group")
.set(pkg.tag(Header.HeaderTag.GROUP))
.up()
.add("rpm:buildhost")
.set(pkg.tag(Header.HeaderTag.BUILDHOST))
.up()
.add("rpm:sourcerpm")
.set(pkg.tag(Header.HeaderTag.SOURCERPM))
.up()
.add("rpm:header-range")
.attr("start", pkg.header().getStartPos())
.attr("end", pkg.header().getEndPos())
.up()
.append(rpmProvides(pkg))
.append(rpmRequires(pkg))
.append(files(pkg))
.up()
)
.flatMapCompletable(directives -> new Update(this.xml).apply(directives));
}
Expand Down
27 changes: 18 additions & 9 deletions src/main/java/com/yegor256/rpm/ReactiveLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
*/
class ReactiveLock {

/**
* Unlock and emit sync object.
*/
private final Object sync = new Object();

/**
* Current state of the lock.
*/
Expand Down Expand Up @@ -63,21 +68,25 @@ public Completable lock() {
/**
* Unlock the lock.
*/
public synchronized void unlock() {
if (this.locked.compareAndSet(true, false)) {
this.tryToEmitNext();
public void unlock() {
synchronized (this.sync) {
if (this.locked.compareAndSet(true, false)) {
this.tryToEmitNext();
}
}
}

/**
* Give a lock to another awaiter.
*/
private synchronized void tryToEmitNext() {
if (!this.locked.get()) {
final CompletableEmitter emitter = this.acquires.poll();
if (emitter != null) {
this.locked.set(true);
emitter.onComplete();
private void tryToEmitNext() {
synchronized (this.sync) {
if (!this.locked.get()) {
final CompletableEmitter emitter = this.acquires.poll();
if (emitter != null) {
this.locked.set(true);
emitter.onComplete();
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/yegor256/rpm/Repomd.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.CompletableSource;
import io.reactivex.rxjava3.core.Single;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
Expand Down Expand Up @@ -121,11 +120,11 @@ private CompletableSource performUpdate(
String.format("/ns:repomd/data[type='%s']", type)
);
final Completable res;
if (!nodes.isEmpty()) {
if (nodes.isEmpty()) {
res = Completable.complete();
} else {
final String location = nodes.get(0).xpath("location/@href").get(0);
res = this.storage.load(location, file);
} else {
res = Completable.complete();
}
final String key = String.format("repodata/%s.xml", type);
final Path gzip = Files.createTempFile("x", ".gz");
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/yegor256/rpm/Rpm.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
import com.yegor256.asto.Storage;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Single;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.locks.Lock;

/**
* The RPM front.
Expand All @@ -44,7 +41,7 @@
* and update all the necessary meta-data files. Right after this,
* your clients will be able to use the package, via {@code yum}:
*
* <pre> rpm.update("nginx.rpm");</pre>
* <pre> rpm.update("nginx.rpm").subscribe();</pre>
*
* That's it.
*
Expand All @@ -60,24 +57,27 @@ public final class Rpm {
/**
* Access lock for primary.xml file.
*/
private final ReactiveLock primary = new ReactiveLock();
private final ReactiveLock primary;

/**
* Access lock for filelists.xml file.
*/
private final ReactiveLock filelists = new ReactiveLock();
private final ReactiveLock filelists;

/**
* Access lock for other.xml file.
*/
private final ReactiveLock other = new ReactiveLock();
private final ReactiveLock other;

/**
* Ctor.
* @param stg The storage
*/
public Rpm(final Storage stg) {
this.storage = stg;
this.other = new ReactiveLock();
this.filelists = new ReactiveLock();
this.primary = new ReactiveLock();
}

/**
Expand Down

0 comments on commit bc789b6

Please sign in to comment.