Subversion Repositories tpanel

Rev

Rev 21 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21 Rev 22
Line 14... Line 14...
14
 * You should have received a copy of the GNU General Public License
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
17
 */
18
 
18
 
-
 
19
#include <string>
19
#include "tvalidatefile.h"
20
#include <vector>
-
 
21
 
20
#include <sys/types.h>
22
#include <sys/types.h>
21
#include <sys/stat.h>
23
#include <sys/stat.h>
-
 
24
 
-
 
25
#include "tvalidatefile.h"
22
#include "terror.h"
26
#include "terror.h"
-
 
27
#include "tresources.h"
23
 
28
 
24
using std::string;
29
using std::string;
-
 
30
using std::vector;
25
 
31
 
26
bool TValidateFile::isValidFile(const string& file)
32
bool TValidateFile::isValidFile(const string& file)
27
{
33
{
28
    DECL_TRACER("TValidateFile::isValid(const string& file)");
34
    DECL_TRACER("TValidateFile::isValid(const string& file)");
29
 
35
 
Line 55... Line 61...
55
 
61
 
56
    mFile.append(name);
62
    mFile.append(name);
57
    return mFile;
63
    return mFile;
58
}
64
}
59
 
65
 
-
 
66
bool TValidateFile::createPath(const string &path)
-
 
67
{
-
 
68
    DECL_TRACER("TValidateFile::createPath(const string &path)");
-
 
69
 
-
 
70
    if (path.length() == 0 || path == ".")
-
 
71
        return true;
-
 
72
 
-
 
73
    vector<string> parts = StrSplit(path, "/");
-
 
74
    vector<string>::iterator iter;
-
 
75
    bool absolut = false;
-
 
76
    string pPart;
-
 
77
 
-
 
78
    if (path[0] == '/')
-
 
79
        absolut = true;
-
 
80
 
-
 
81
    for (iter = parts.begin(); iter != parts.end(); ++iter)
-
 
82
    {
-
 
83
        if ((pPart.empty() && absolut) || !pPart.empty())
-
 
84
            pPart += "/" + *iter;
-
 
85
        else
-
 
86
            pPart += *iter;
-
 
87
 
-
 
88
        // Test for existence of the path part and whether it is a file or a directory.
-
 
89
        struct stat buffer;
-
 
90
 
-
 
91
        if (stat (pPart.data(), &buffer) == 0)      // If there exists something test what it is.
-
 
92
        {
-
 
93
            if (!S_ISDIR(buffer.st_mode) && !S_ISLNK(buffer.st_mode))
-
 
94
            {
-
 
95
                MSG_WARNING(pPart << " is not a directory!");
-
 
96
                return false;
-
 
97
            }
-
 
98
        }
-
 
99
        else    // We try to create it
-
 
100
        {
-
 
101
            if (mkdir(pPart.c_str(), S_IRWXU | S_IRWXG | S_IXOTH | S_IROTH) == -1)
-
 
102
            {
-
 
103
                MSG_ERROR("Error creating directory " << pPart << ": " << strerror(errno));
-
 
104
                return false;
-
 
105
            }
-
 
106
        }
-
 
107
    }
-
 
108
 
-
 
109
    return true;
-
 
110
 
-
 
111
}