2014-05-22 21 views
0

目前,我有一個應用程序,我正在從Linux移植到Windows。我寧願儘可能使用提升。移植訪問(2)Linux系統調用boost :: filesystem

我目前有以下片段,我想要移植,這是不言自明的。

return access(backupFile.c_str(), R_OK) == 0; 

問題是,似乎boost :: filesystem沒有直接的等價物。也就是說,我可以做到以下幾點:

namespace fs = boost::filesystem; 

if (!fs::is_regular_file(filename, ec)) 
    return false; 

fs::file_status s = fs::status(filename); 

// Which permissions should I be testing for? 
if (s.permissions() == ???) 

()枚舉可以發現here的權限。但是,當我閱讀它時,它不是直接轉換,因爲我必須測試以查看我是否在適用組中,並且該組的權限是否可用。

有沒有更簡單的方法?我對行爲的解釋是否正確?

(當然,我總是可以嘗試打開文件閱讀,但這不是這個問題的目標)。

回答

1

既然你要移植到Windows,根據微軟_access()秒參數是:

00 Existence only 
02 Write-only 
04 Read-only 
06 Read and write 

所以,我認爲你應該使用符合上述考慮從權限下面引用鏈接提升權限:

Windows: All permissions except write are currently ignored. There is only a single 
write permission; setting write permission for owner, group, or others sets write 
permission for all, and removing write permission for owner, group, or others removes 
write permission for all. 

或者,您可能想要使用Microsoft指定的參數繼續使用Windows版本的access()(_access()用於MS編譯器)。

你可能想要考慮的另一類是ATL CAccessToken

+0

好戲。這對WinCE也有效嗎? – Damien

+0

我沒有與CE工作多年,我不記得這一個,但如果遲到版本沒有它,也有GetFileAttributes()API,你可能想檢查:) – DNT

+0

完成。解決我的問題。 – Damien