18.03.2013 - Bug fixes, add in/out speed diagnostic to PIProtocol, fixed PIConsole tab switch segfault, PIObject EVENT / EVENT_HANDLER mechanism update - new EVENT macros that use EVENT_HANDLER with raiseEvent implementation.
This allow compile check event for CONNECT and use EVENT as CONNECT target, also raise event now is simple execute EVENT function.
This commit is contained in:
30
pidir.cpp
Executable file → Normal file
30
pidir.cpp
Executable file → Normal file
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Directory
|
||||
Copyright (C) 2012 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2013 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -78,17 +78,11 @@ PIDir & PIDir::cleanPath() {
|
||||
open();
|
||||
return *this;
|
||||
}
|
||||
path_.replaceAll(PIString(separator) + PIString(separator), PIString(separator));
|
||||
bool isAbs = isAbsolute();
|
||||
for (uint i = p.size() - 1; i > 0; --i) {
|
||||
if (p[i] == separator && p[i - 1] == separator) {
|
||||
p.cutLeft(i);
|
||||
isAbs = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
PIStringList l = PIString(p).split(separator);
|
||||
l.removeStrings(".");
|
||||
l.removeStrings("");
|
||||
l.removeAll(".");
|
||||
l.removeAll("");
|
||||
bool found = true;
|
||||
while (found) {
|
||||
found = false;
|
||||
@@ -118,20 +112,19 @@ PIDir & PIDir::cleanPath() {
|
||||
|
||||
PIDir & PIDir::cd(const PIString & path) {
|
||||
if (path_.size() == 0) return *this;
|
||||
if (path_[path_.size() - 1] == separator) path_ << path;
|
||||
else path_ << separator << path;
|
||||
if (path_[path_.size() - 1] != separator) path_ << separator;
|
||||
path_ << path;
|
||||
return cleanPath();
|
||||
}
|
||||
|
||||
|
||||
bool PIDir::mkDir(bool withParents) {
|
||||
PIDir d = cleanedPath();
|
||||
string p = d.path_;
|
||||
PIString tp;
|
||||
int ret;
|
||||
bool isAbs = isAbsolute();
|
||||
if (withParents) {
|
||||
PIStringList l = PIString(p).split(separator);
|
||||
PIStringList l = d.path_.split(separator);
|
||||
for (int i = l.size_s() - 1; i >= 0; --i) {
|
||||
if (i > 1) tp = PIStringList(l).remove(i, l.size_s() - i).join(separator);
|
||||
else {
|
||||
@@ -143,19 +136,18 @@ bool PIDir::mkDir(bool withParents) {
|
||||
for (int j = i + 1; j <= l.size_s(); ++j) {
|
||||
tp = PIStringList(l).remove(j, l.size_s() - j).join(separator);
|
||||
//cout << tp << endl;
|
||||
p = tp.stdString();
|
||||
ret = mkdir(p.c_str(), 16877);
|
||||
ret = mkdir(tp.data(), 16877);
|
||||
if (ret == 0) continue;
|
||||
printf("[PIDir] mkDir(\"%s\") error: %s\n", p.c_str(), strerror(errno));
|
||||
printf("[PIDir] mkDir(\"%s\") error: %s\n", d.path_.data(), strerror(errno));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
};
|
||||
}
|
||||
} else {
|
||||
ret = mkdir(p.c_str(), 16877);
|
||||
ret = mkdir(d.path_.data(), 16877);
|
||||
if (ret == 0) return true;
|
||||
printf("[PIDir] mkDir(\"%s\") error: %s\n", p.c_str(), strerror(errno));
|
||||
printf("[PIDir] mkDir(\"%s\") error: %s\n", d.path_.data(), strerror(errno));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user