Annotation of truecrypt/platform/unix/directory.cpp, revision 1.1.1.2

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 <sys/stat.h>
1.1.1.2 ! root       10: #include <sys/types.h>
        !            11: #include <dirent.h>
        !            12: #include <errno.h>
1.1       root       13: #include "System.h"
                     14: #include "Platform/Directory.h"
1.1.1.2 ! root       15: #include "Platform/Finally.h"
1.1       root       16: #include "Platform/SystemException.h"
                     17: 
                     18: namespace TrueCrypt
                     19: {
1.1.1.2 ! root       20:        static Mutex ReadDirMutex;      // readdir_r() may be unsafe on some systems
        !            21: 
1.1       root       22:        void Directory::Create (const DirectoryPath &path)
                     23:        {
                     24:                string p = path;
                     25:                throw_sys_sub_if (mkdir (p.c_str(), S_IRUSR | S_IWUSR | S_IXUSR) == -1, p);
                     26:        }
                     27: 
                     28:        DirectoryPath Directory::AppendSeparator (const DirectoryPath &path)
                     29:        {
                     30:                wstring p (path);
                     31: 
                     32:                if (p.find_last_of (L'/') + 1 != p.size())
                     33:                        return p + L'/';
                     34: 
                     35:                return p;
                     36:        }
                     37: 
                     38:        FilePathList Directory::GetFilePaths (const DirectoryPath &path)
                     39:        {
1.1.1.2 ! root       40:                DIR *dir = opendir (string (path).c_str());
        !            41:                throw_sys_sub_if (!dir, wstring (path));
        !            42:                finally_do_arg (DIR*, dir, { closedir (finally_arg); });
        !            43: 
        !            44:                ScopeLock lock (ReadDirMutex);
        !            45: 
        !            46:                FilePathList files;
        !            47:                struct dirent *dirEntry;
        !            48:                errno = 0;
        !            49:                while ((dirEntry = readdir (dir)) != nullptr)
        !            50:                {
        !            51:                        shared_ptr <FilePath> filePath (new FilePath (string (AppendSeparator (path)) + string (dirEntry->d_name)));
        !            52:                        
        !            53:                        if (filePath->IsFile())
        !            54:                                files.push_back (filePath);
        !            55: 
        !            56:                        errno = 0;
        !            57:                }
        !            58: 
        !            59:                throw_sys_sub_if (errno != 0, wstring (path));
        !            60:                return files;
1.1       root       61:        }
                     62: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.