|
|
1.1 root 1: /*
2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
3:
4: Governed by the TrueCrypt License 2.4 the full text of which is contained
5: in the file License.txt included in TrueCrypt binary and source code
6: distribution packages.
7: */
8:
9: #include "Platform/FilesystemPath.h"
10: #include "Platform/SystemException.h"
11: #include "Platform/StringConverter.h"
12: #include <sys/stat.h>
13:
14: namespace TrueCrypt
15: {
16: void FilesystemPath::Delete () const
17: {
18: throw_sys_sub_if (remove (string (*this).c_str()) == -1, Path);
19: }
20:
21: FilesystemPathType::Enum FilesystemPath::GetType () const
22: {
23: // Strip trailing directory separator
24: wstring path = Path;
25: size_t pos = path.find_last_not_of (L'/');
26: if (path.size() > 2 && pos != path.size() - 1)
27: path = path.substr (0, pos + 1);
28:
29: struct stat statData;
30: throw_sys_sub_if (stat (StringConverter::ToSingle (path).c_str(), &statData) != 0, Path);
31:
32: if (S_ISREG (statData.st_mode)) return FilesystemPathType::File;
33: if (S_ISDIR (statData.st_mode)) return FilesystemPathType::Directory;
34: if (S_ISCHR (statData.st_mode)) return FilesystemPathType::CharacterDevice;
35: if (S_ISBLK (statData.st_mode)) return FilesystemPathType::BlockDevice;
36: if (S_ISLNK (statData.st_mode)) return FilesystemPathType::SymbolickLink;
37:
38: return FilesystemPathType::Unknown;
39: }
40: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.