PIFile::readAll release

patch deploy_tool: ignore libc.so and take last dpkg dependency instead of first
This commit is contained in:
2025-09-05 21:46:44 +03:00
parent 91144ad338
commit a299ada873
5 changed files with 26 additions and 41 deletions

View File

@@ -252,32 +252,7 @@ llong PIFile::readAll(void * data) {
}
PIByteArray PIFile::readAll(bool forceRead) {
PIByteArray a;
llong cp = pos();
if (forceRead) {
seekToBegin();
for (;;) {
uchar byte = static_cast<uchar>(fgetc(PRIVATE->fd));
if (feof(PRIVATE->fd) || ferror(PRIVATE->fd)) break;
a.push_back(byte);
}
seek(cp);
return a;
}
llong s = size();
if (s < 0) return a;
a.resize(s);
seekToBegin();
auto _r = fread(a.data(), 1, s, PRIVATE->fd);
NO_UNUSED(_r);
seek(cp);
if (s >= 0) a.resize(s);
return a;
}
PIByteArray PIFile::_readAll() {
PIByteArray PIFile::readAll() {
if (!isOpened()) return {};
llong prev_pos = pos();
PIByteArray ret, buffer(4_KiB);
@@ -647,10 +622,10 @@ bool PIFile::applyFileInfo(const PIString & path, const PIFile::FileInfo & info)
}
PIByteArray PIFile::readAll(const PIString & path, bool forceRead) {
PIByteArray PIFile::readAll(const PIString & path) {
PIFile f(path, PIIODevice::ReadOnly);
if (!f.isOpened()) return PIByteArray();
return f.readAll(forceRead);
return f.readAll();
}

View File

@@ -225,10 +225,7 @@ public:
//! \~english Read all file content to byte array and return it. Position leaved unchanged
//! \~russian Читает всё содержимое файла и возвращает его как массив байтов. Позиция остаётся неизменной
PIByteArray readAll(bool forceRead = false);
PIByteArray _readAll();
PIByteArray readAll();
//! \~english Set file path to "path" and reopen file if need
//! \~russian Устанавливает путь файла на "path" и переоткрывает его при необходимости
@@ -297,7 +294,7 @@ public:
//! \~english Read all file content at path "path" to byte array and return it.
//! \~russian Читает всё содержимое файла по пути "path" и возвращает его как массив байтов.
static PIByteArray readAll(const PIString & path, bool forceRead = false);
static PIByteArray readAll(const PIString & path);
//! \~english Clear file at path "path" and write "data", returns written bytes.
//! \~russian Очищает файл по пути "path", пишет туда "data" и возвращает количество записанных байт.

View File

@@ -234,7 +234,7 @@ PIString PISystemInfo::machineKey() {
PISystemInfo * si = instance();
PIByteArray salt;
PIString conf = confDir() + "/.pip_machine_salt";
if (PIFile::isExists(conf)) salt = PIFile::readAll(conf, false);
if (PIFile::isExists(conf)) salt = PIFile::readAll(conf);
if (salt.size_s() != SALT_SIZE) {
salt = generateSalt();
PIFile::writeAll(conf, salt);

View File

@@ -86,8 +86,9 @@ int main(int argc, char * argv[]) {
if (argc < 2) return 0;
PIFile f(argv[1], PIIODevice::ReadOnly);
piCout << "read" << f.path();
auto fc = f._readAll();
piCout << fc.size() << PIString::fromUTF8(fc.resized(32));
auto fc = f.readAll();
piCout << fc.size();
if (!fc.isEmpty()) piCout << PIString::fromUTF8(fc.resized(32));
return 0;
@@ -174,7 +175,7 @@ int main(int argc, char * argv[]) {
// return 0;
PIRegularExpression pire("(?:\\/\\/\\s*)?.*\\n?(?:\\bfunction\\b)\\s*(?<name>\\b\\w+\\b)\\s*(?:\\((?<args>[^;()]*?)\\))",
PIRegularExpression::Multiline);
PIString subj = PIString::fromUTF8(PIFile::readAll("telegram.qs", false));
PIString subj = PIString::fromUTF8(PIFile::readAll("telegram.qs"));
piCout << "Pattern:" << pire.pattern();
piCout << "Valid:" << pire.isValid();

View File

@@ -463,11 +463,14 @@ bool procDpkg(const PIString & l) {
fi.path = l;
PIString cmd = dpkg + dpkgdir + " -S " + fi.name() + ign_err_suffix;
// PICout(true) << cmd;
PIString vs = execute(cmd);
PIString vs = execute(cmd).trim();
if (!vs.isEmpty()) {
vs = vs.left(vs.find(":"));
if (!vs.isEmpty() && !vs.endsWith("-cross")) all_deps << vs;
return true;
PIStringList lines = vs.split('\n').reverse();
for (auto l: lines) {
l = l.left(l.find(":"));
if (!l.isEmpty() && !l.endsWith("-cross")) all_deps << vs;
return true;
}
}
// piCout << "No dep on" << l;
return false;
@@ -787,7 +790,16 @@ int main(int argc, char * argv[]) {
out_dir.replaceAll("/", "\\");
#endif
PIVector<PIString> clibs = all_libs.toVector();
static PIStringList ignore_libs({"libc.so"});
for (auto l: clibs) {
bool ignore_lib = false;
for (auto il: ignore_libs) {
if (l.startsWith(il)) {
ignore_lib = true;
break;
}
}
if (ignore_lib) continue;
PIFile::FileInfo fi;
fi.path = l;
#ifdef WINDOWS