PIFile::readAll release
patch deploy_tool: ignore libc.so and take last dpkg dependency instead of first
This commit is contained in:
@@ -252,32 +252,7 @@ llong PIFile::readAll(void * data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIByteArray PIFile::readAll(bool forceRead) {
|
PIByteArray PIFile::readAll() {
|
||||||
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() {
|
|
||||||
if (!isOpened()) return {};
|
if (!isOpened()) return {};
|
||||||
llong prev_pos = pos();
|
llong prev_pos = pos();
|
||||||
PIByteArray ret, buffer(4_KiB);
|
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);
|
PIFile f(path, PIIODevice::ReadOnly);
|
||||||
if (!f.isOpened()) return PIByteArray();
|
if (!f.isOpened()) return PIByteArray();
|
||||||
return f.readAll(forceRead);
|
return f.readAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -225,10 +225,7 @@ public:
|
|||||||
|
|
||||||
//! \~english Read all file content to byte array and return it. Position leaved unchanged
|
//! \~english Read all file content to byte array and return it. Position leaved unchanged
|
||||||
//! \~russian Читает всё содержимое файла и возвращает его как массив байтов. Позиция остаётся неизменной
|
//! \~russian Читает всё содержимое файла и возвращает его как массив байтов. Позиция остаётся неизменной
|
||||||
PIByteArray readAll(bool forceRead = false);
|
PIByteArray readAll();
|
||||||
|
|
||||||
PIByteArray _readAll();
|
|
||||||
|
|
||||||
|
|
||||||
//! \~english Set file path to "path" and reopen file if need
|
//! \~english Set file path to "path" and reopen file if need
|
||||||
//! \~russian Устанавливает путь файла на "path" и переоткрывает его при необходимости
|
//! \~russian Устанавливает путь файла на "path" и переоткрывает его при необходимости
|
||||||
@@ -297,7 +294,7 @@ public:
|
|||||||
|
|
||||||
//! \~english Read all file content at path "path" to byte array and return it.
|
//! \~english Read all file content at path "path" to byte array and return it.
|
||||||
//! \~russian Читает всё содержимое файла по пути "path" и возвращает его как массив байтов.
|
//! \~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.
|
//! \~english Clear file at path "path" and write "data", returns written bytes.
|
||||||
//! \~russian Очищает файл по пути "path", пишет туда "data" и возвращает количество записанных байт.
|
//! \~russian Очищает файл по пути "path", пишет туда "data" и возвращает количество записанных байт.
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ PIString PISystemInfo::machineKey() {
|
|||||||
PISystemInfo * si = instance();
|
PISystemInfo * si = instance();
|
||||||
PIByteArray salt;
|
PIByteArray salt;
|
||||||
PIString conf = confDir() + "/.pip_machine_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) {
|
if (salt.size_s() != SALT_SIZE) {
|
||||||
salt = generateSalt();
|
salt = generateSalt();
|
||||||
PIFile::writeAll(conf, salt);
|
PIFile::writeAll(conf, salt);
|
||||||
|
|||||||
7
main.cpp
7
main.cpp
@@ -86,8 +86,9 @@ int main(int argc, char * argv[]) {
|
|||||||
if (argc < 2) return 0;
|
if (argc < 2) return 0;
|
||||||
PIFile f(argv[1], PIIODevice::ReadOnly);
|
PIFile f(argv[1], PIIODevice::ReadOnly);
|
||||||
piCout << "read" << f.path();
|
piCout << "read" << f.path();
|
||||||
auto fc = f._readAll();
|
auto fc = f.readAll();
|
||||||
piCout << fc.size() << PIString::fromUTF8(fc.resized(32));
|
piCout << fc.size();
|
||||||
|
if (!fc.isEmpty()) piCout << PIString::fromUTF8(fc.resized(32));
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
@@ -174,7 +175,7 @@ int main(int argc, char * argv[]) {
|
|||||||
// return 0;
|
// return 0;
|
||||||
PIRegularExpression pire("(?:\\/\\/\\s*)?.*\\n?(?:\\bfunction\\b)\\s*(?<name>\\b\\w+\\b)\\s*(?:\\((?<args>[^;()]*?)\\))",
|
PIRegularExpression pire("(?:\\/\\/\\s*)?.*\\n?(?:\\bfunction\\b)\\s*(?<name>\\b\\w+\\b)\\s*(?:\\((?<args>[^;()]*?)\\))",
|
||||||
PIRegularExpression::Multiline);
|
PIRegularExpression::Multiline);
|
||||||
PIString subj = PIString::fromUTF8(PIFile::readAll("telegram.qs", false));
|
PIString subj = PIString::fromUTF8(PIFile::readAll("telegram.qs"));
|
||||||
|
|
||||||
piCout << "Pattern:" << pire.pattern();
|
piCout << "Pattern:" << pire.pattern();
|
||||||
piCout << "Valid:" << pire.isValid();
|
piCout << "Valid:" << pire.isValid();
|
||||||
|
|||||||
@@ -463,12 +463,15 @@ bool procDpkg(const PIString & l) {
|
|||||||
fi.path = l;
|
fi.path = l;
|
||||||
PIString cmd = dpkg + dpkgdir + " -S " + fi.name() + ign_err_suffix;
|
PIString cmd = dpkg + dpkgdir + " -S " + fi.name() + ign_err_suffix;
|
||||||
// PICout(true) << cmd;
|
// PICout(true) << cmd;
|
||||||
PIString vs = execute(cmd);
|
PIString vs = execute(cmd).trim();
|
||||||
if (!vs.isEmpty()) {
|
if (!vs.isEmpty()) {
|
||||||
vs = vs.left(vs.find(":"));
|
PIStringList lines = vs.split('\n').reverse();
|
||||||
if (!vs.isEmpty() && !vs.endsWith("-cross")) all_deps << vs;
|
for (auto l: lines) {
|
||||||
|
l = l.left(l.find(":"));
|
||||||
|
if (!l.isEmpty() && !l.endsWith("-cross")) all_deps << vs;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// piCout << "No dep on" << l;
|
// piCout << "No dep on" << l;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -787,7 +790,16 @@ int main(int argc, char * argv[]) {
|
|||||||
out_dir.replaceAll("/", "\\");
|
out_dir.replaceAll("/", "\\");
|
||||||
#endif
|
#endif
|
||||||
PIVector<PIString> clibs = all_libs.toVector();
|
PIVector<PIString> clibs = all_libs.toVector();
|
||||||
|
static PIStringList ignore_libs({"libc.so"});
|
||||||
for (auto l: clibs) {
|
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;
|
PIFile::FileInfo fi;
|
||||||
fi.path = l;
|
fi.path = l;
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
|||||||
Reference in New Issue
Block a user