Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
/ jdk22u Public archive

Commit

Permalink
8295111: dpkg appears to have problems resolving symbolically linked …
Browse files Browse the repository at this point in the history
…native libraries

Backport-of: 32946e1882e9b22c983cbba3c6bda3cc7295946a
  • Loading branch information
Alexey Semenyuk authored and shipilev committed Apr 23, 2024
1 parent bf8146e commit a93848c
Showing 1 changed file with 41 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -201,6 +201,24 @@ protected void initLibProvidersLookup(
Map<String, ? super Object> params,
LibProvidersLookup libProvidersLookup) {

libProvidersLookup.setPackageLookup(file -> {
Path realPath = file.toRealPath();

try {
// Try the real path first as it works better on newer Ubuntu versions
return findProvidingPackages(realPath);
} catch (IOException ex) {
// Try the default path if differ
if (!realPath.toString().equals(file.toString())) {
return findProvidingPackages(file);
} else {
throw ex;
}
}
});
}

private static Stream<String> findProvidingPackages(Path file) throws IOException {
//
// `dpkg -S` command does glob pattern lookup. If not the absolute path
// to the file is specified it might return mltiple package names.
Expand Down Expand Up @@ -243,32 +261,30 @@ protected void initLibProvidersLookup(
// 4. Arch suffix should be stripped from accepted package names.
//

libProvidersLookup.setPackageLookup(file -> {
Set<String> archPackages = new HashSet<>();
Set<String> otherPackages = new HashSet<>();

Executor.of(TOOL_DPKG, "-S", file.toString())
.saveOutput(true).executeExpectSuccess()
.getOutput().forEach(line -> {
Matcher matcher = PACKAGE_NAME_REGEX.matcher(line);
if (matcher.find()) {
String name = matcher.group(1);
if (name.endsWith(":" + DEB_ARCH)) {
// Strip arch suffix
name = name.substring(0,
name.length() - (DEB_ARCH.length() + 1));
archPackages.add(name);
} else {
otherPackages.add(name);
}
Set<String> archPackages = new HashSet<>();
Set<String> otherPackages = new HashSet<>();

Executor.of(TOOL_DPKG, "-S", file.toString())
.saveOutput(true).executeExpectSuccess()
.getOutput().forEach(line -> {
Matcher matcher = PACKAGE_NAME_REGEX.matcher(line);
if (matcher.find()) {
String name = matcher.group(1);
if (name.endsWith(":" + DEB_ARCH)) {
// Strip arch suffix
name = name.substring(0,
name.length() - (DEB_ARCH.length() + 1));
archPackages.add(name);
} else {
otherPackages.add(name);
}
});
}
});

if (!archPackages.isEmpty()) {
return archPackages.stream();
}
return otherPackages.stream();
});
if (!archPackages.isEmpty()) {
return archPackages.stream();
}
return otherPackages.stream();
}

@Override
Expand Down

1 comment on commit a93848c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.