Skip to content

Commit 5136294

Browse files
committed
Make cached library a warning
Ref: #15 (comment)
1 parent d8bdcd4 commit 5136294

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

MacDependency/MachOModel.mm

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ - (id) initWithFilename:(std::string&)filename command:(DylibCommand*)aCommand d
5151
NSString* log = [NSString stringWithFormat:NSLocalizedString(@"ERR_ARCHITECTURE_MISMATCH", nil), filename.c_str(), [parent name]];
5252
[aDocument appendLogLine:log withModel:self state:state];
5353
}
54-
55-
} catch (MachOException& exc) {
56-
[self setStateWithWarning:isWeakReference];
54+
} catch (MachOException& exc) {
55+
[self setStateWithWarning:isWeakReference || exc.isWarning()];
5756
NSString* log = [NSString stringWithStdString:exc.getCause()];
5857
[aDocument appendLogLine:log withModel:self state:state];
5958
// distinguish between weak and strong. In both cases append to tree with a status color
@@ -176,10 +175,10 @@ - (NSColor*) textColor {
176175
NSColor* color;
177176
switch(state) {
178177
case StateWarning:
179-
color = [NSColor systemOrangeColor];
178+
color = [NSColor systemYellowColor];
180179
break;
181180
case StateError:
182-
color = [NSColor systemOrangeColor];
181+
color = [NSColor systemRedColor];
183182
break;
184183
default:
185184
color = [NSColor labelColor];

MachO/internalfile.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "internalfile.h"
22
#include "machoexception.h"
33

4+
#include <dlfcn.h>
5+
46
// use reference counting to reuse files for all used architectures
57
InternalFile* InternalFile::create(InternalFile* file) {
68
file->counter++;
@@ -24,9 +26,13 @@ filename(filename), counter(1)
2426
// open file handle
2527
file.open(this->filename, std::ios_base::in | std::ios_base::binary);
2628
if (file.fail()) {
27-
std::ostringstream error;
28-
error << "Couldn't open file '" << filename << "'.";
29-
throw MachOException(error.str());
29+
void* dylib = dlopen(this->filename.c_str(), RTLD_LAZY);
30+
if (dylib) {
31+
dlclose(dylib);
32+
throw MachOException("System cached library '" + filename + "'.", true);
33+
} else {
34+
throw MachOException("Couldn't open file '" + filename + "'.");
35+
}
3036
}
3137

3238
struct stat buffer;

MachO/machoexception.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "machoexception.h"
22

3-
MachOException::MachOException(const std::string& cause) : cause(cause)
3+
MachOException::MachOException(const std::string& cause) : cause(cause), warning(false)
44
{
55
}
66

7+
MachOException::MachOException(const std::string& cause, bool warning) : cause(cause), warning(warning)
8+
{
9+
}

MachO/machoexception.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ class EXPORT MachOException
77
{
88
public:
99
MachOException(const std::string&);
10+
MachOException(const std::string&, bool warning);
1011
const std::string& getCause() { return cause; }
12+
const bool isWarning() { return warning; }
1113
private:
1214
const std::string cause;
15+
bool warning;
1316
};
1417

1518
#endif // MACHOEXCEPTION_H

0 commit comments

Comments
 (0)