当执行驱动器的递归目录扫描以通过运行sudo
下的程序可执行文件为每个文件生成哈希时,我发现1,000个文件正在抛出“权限被拒绝”错误。
我的问题:这是设计,为什么sudo无法读取文件?我正在做什么,因为文件可能在扫描期间被加密或当前正在使用?
当我编译到Mac OSX并在sudo
下执行相同的扫描时,我没有这个问题,只有Linux。
Distro: 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
拒绝权限的文件示例:
Can't open file: "/sys/class/gpio/unexport"
MSG: "Permission denied"
Can't open file: "/sys/class/gpio/export"
MSG: "Permission denied"
权限设置示例:
/sys/class/gpio$ ls -al
total 0
drwxr-xr-x 2 root root 0 Oct 5 04:51 .
drwxr-xr-x 57 root root 0 Oct 4 11:25 ..
--w------- 1 root root 4096 Oct 5 04:51 export
--w------- 1 root root 4096 Oct 5 04:51 unexport
MD5文件读取失败的函数:
QByteArray MD5(QString sPath)
{
QByteArray resultMD5 = NULL;
QFile* file = new QFile(sPath);
if(file->open(QIODevice::ReadOnly))
{
QCryptographicHash* pHashMD5 = NULL;
resultMD5 = pHashMD5->hash(file->readAll(),QCryptographicHash::Md5);
file->close();
//Clean up pointer
delete pHashMD5;
delete file;
}
else
{
qDebug() << "Can't open file: " << sPath;
qDebug() << "MSG: " << file->errorString();
file->close();
delete file;
}
return resultMD5;
}
答案 0 :(得分:2)