Skip to content

Commit

Permalink
Check hasShebang only on files
Browse files Browse the repository at this point in the history
  • Loading branch information
probonopd committed Aug 28, 2023
1 parent 45fe33c commit 15545b2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Executable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ bool Executable::isExecutable(const QString& path) {

bool Executable::hasShebang(const QString& path) {
QFile file(path);
QFileInfo fileInfo(path);

// If it is a directory, it cannot have a shebang, so return false
if (fileInfo.isDir()) {
qDebug() << "File is a directory, so it cannot have a shebang.";
return false;
}

// If it is a symlink, we need to check the target
if (fileInfo.isSymLink()) {
qDebug() << "File is a symlink, so we need to check the target.";
QString target = fileInfo.symLinkTarget();
qDebug() << "Target:" << target;
return hasShebang(target);
}

qDebug() << "Checking file:" << path;
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "Failed to open file:" << path;
Expand Down

0 comments on commit 15545b2

Please sign in to comment.