Skip to content

Commit c890635

Browse files
committed
Support downloading libraries that are symlinks to other files
1 parent 2919c56 commit c890635

1 file changed

Lines changed: 40 additions & 6 deletions

File tree

src/program/AutoDetect.cpp

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ void AutoDetect::game_libraries(Context *context)
106106
libUrl = "http://security.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0.0_1.0.2n-1ubuntu5.13_amd64.deb";
107107
}
108108
}
109+
else if (missing_lib == "libldap-2.4.so.2") {
110+
if (gameArch == BT_ELF32) {
111+
libUrl = "http://security.ubuntu.com/ubuntu/pool/main/o/openldap/libldap-2.4-2_2.4.49+dfsg-2ubuntu1.10_i386.deb";
112+
}
113+
else {
114+
libUrl = "http://security.ubuntu.com/ubuntu/pool/main/o/openldap/libldap-2.4-2_2.4.49+dfsg-2ubuntu1.10_amd64.deb";
115+
}
116+
}
117+
else if (missing_lib == "liblber-2.4.so.2") {
118+
if (gameArch == BT_ELF32) {
119+
libUrl = "http://security.ubuntu.com/ubuntu/pool/main/o/openldap/libldap-2.4-2_2.4.49+dfsg-2ubuntu1.10_i386.deb";
120+
}
121+
else {
122+
libUrl = "http://security.ubuntu.com/ubuntu/pool/main/o/openldap/libldap-2.4-2_2.4.49+dfsg-2ubuntu1.10_amd64.deb";
123+
}
124+
}
109125
else {
110126
return;
111127
}
@@ -117,12 +133,9 @@ void AutoDetect::game_libraries(Context *context)
117133
oss_lib << " && ar -x --output ${TMPDIR:-/tmp} ${TMPDIR:-/tmp}/" << fileFromPath(libUrl) << " data.tar.xz";
118134

119135
std::string libFile = (gameArch == BT_ELF32) ? "./usr/lib/i386-linux-gnu/" : "./usr/lib/x86_64-linux-gnu/";
120-
libFile.append(missing_lib);
121136

122137
oss_lib << " && tar -xf ${TMPDIR:-/tmp}/data.tar.xz -C ${TMPDIR:-/tmp} " << libFile;
123-
oss_lib << " && mv ${TMPDIR:-/tmp}/" << libFile << " ";
124-
oss_lib << ((gameArch == BT_ELF32) ? context->config.extralib32dir : context->config.extralib64dir);
125-
138+
126139
int status;
127140
queryCmd(oss_lib.str(), &status);
128141

@@ -131,11 +144,32 @@ void AutoDetect::game_libraries(Context *context)
131144
return;
132145
}
133146

134-
std::string old_missing_lib = missing_lib;
135-
missing_lib = queryCmd(oss_ml.str());
147+
/* The extracted library may be a symlink to another library file, so
148+
* move all the symlink chain to the real file */
149+
std::string current_lib = missing_lib;
136150

151+
while (!current_lib.empty()) {
152+
/* Get the symlink if any, or it returns empty string */
153+
std::ostringstream oss_sym;
154+
oss_sym << "readlink ${TMPDIR:-/tmp}/" << libFile << current_lib;
155+
156+
std::string symlink_lib = queryCmd(oss_sym.str());
157+
158+
/* Move the library file */
159+
std::ostringstream oss_move;
160+
oss_move << "mv ${TMPDIR:-/tmp}/" << libFile << current_lib << " ";
161+
oss_move << ((gameArch == BT_ELF32) ? context->config.extralib32dir : context->config.extralib64dir);
162+
163+
queryCmd(oss_move.str());
164+
165+
current_lib = symlink_lib;
166+
}
167+
137168
/* Check if for some reason, adding the library still shows as missing,
138169
* to prevent a potential softlock */
170+
std::string old_missing_lib = missing_lib;
171+
missing_lib = queryCmd(oss_ml.str());
172+
139173
if (old_missing_lib == missing_lib) {
140174
std::cerr << "Loading library " << missing_lib << " did not work, exiting." << std::endl;
141175
return;

0 commit comments

Comments
 (0)