Добавлен новый параметр для ограничения файлов по размеру
This commit is contained in:
parent
dedfe11200
commit
4b18136acf
4 changed files with 28 additions and 4 deletions
|
|
@ -3,7 +3,8 @@
|
||||||
"logfile": "/var/log/dwatch.log",
|
"logfile": "/var/log/dwatch.log",
|
||||||
"watch": [
|
"watch": [
|
||||||
{
|
{
|
||||||
"path": "/home/alexander/Programming/work/dwatch"
|
"path": "/home/alexander/Programming/work/dwatch",
|
||||||
|
"size": 512
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,7 @@ private:
|
||||||
struct Watch {
|
struct Watch {
|
||||||
string path;
|
string path;
|
||||||
string[] rules;
|
string[] rules;
|
||||||
|
ulong size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _global;
|
bool _global;
|
||||||
|
|
@ -184,7 +185,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
tempMountPoints.insert(systemMountPoint);
|
tempMountPoints.insert(systemMountPoint);
|
||||||
_watch ~= Watch(watch.path, watch.rules.get.dup);
|
_watch ~= Watch(watch.path, watch.rules.get.dup, watch.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
_mountPoints = tempMountPoints.array;
|
_mountPoints = tempMountPoints.array;
|
||||||
|
|
@ -215,6 +216,9 @@ public:
|
||||||
info("База данных: ", _database);
|
info("База данных: ", _database);
|
||||||
foreach (watch; _watch) {
|
foreach (watch; _watch) {
|
||||||
info("Отслеживание директории: ", watch.path);
|
info("Отслеживание директории: ", watch.path);
|
||||||
|
if (watch.size > 0) {
|
||||||
|
infof(" Отслеживаемые файлы имеют установленное ограничение в %dK", watch.size);
|
||||||
|
}
|
||||||
if (watch.rules.length >0) {
|
if (watch.rules.length >0) {
|
||||||
info(" Правила отслеживания файлов в директории (нотация правил Git):");
|
info(" Правила отслеживания файлов в директории (нотация правил Git):");
|
||||||
}
|
}
|
||||||
|
|
@ -294,11 +298,13 @@ public:
|
||||||
} else {
|
} else {
|
||||||
string childPath;
|
string childPath;
|
||||||
string[] rules;
|
string[] rules;
|
||||||
|
ulong size;
|
||||||
|
|
||||||
foreach (Watch watch; _watch) {
|
foreach (Watch watch; _watch) {
|
||||||
if (path.startsWith(watch.path)) {
|
if (path.startsWith(watch.path)) {
|
||||||
childPath = path[watch.path.length .. $];
|
childPath = path[watch.path.length .. $];
|
||||||
rules = watch.rules;
|
rules = watch.rules;
|
||||||
|
size = watch.size;
|
||||||
trace("Кандидат для отслеживания: ", childPath);
|
trace("Кандидат для отслеживания: ", childPath);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -310,7 +316,9 @@ public:
|
||||||
// Получение информации о процессе (паспорт процесса)
|
// Получение информации о процессе (паспорт процесса)
|
||||||
// key как out объект, получение данных из функции
|
// key как out объект, получение данных из функции
|
||||||
if (getDevIno(fd, key, pid)) {
|
if (getDevIno(fd, key, pid)) {
|
||||||
if (key !in _gMap) {
|
if (size > 0 && key.getSize() > size) {
|
||||||
|
warningf("Файл пропущен, так как размер превышает допустимое ограничение: %s - %.3fK", path, key.getSize());
|
||||||
|
} else if (key !in _gMap) {
|
||||||
// Получение имени процесса
|
// Получение имени процесса
|
||||||
auto procName = readProcComm(pid);
|
auto procName = readProcComm(pid);
|
||||||
// Получение идентификаторов пользователя
|
// Получение идентификаторов пользователя
|
||||||
|
|
|
||||||
|
|
@ -78,11 +78,13 @@ final class DWWatch
|
||||||
private:
|
private:
|
||||||
string _path;
|
string _path;
|
||||||
DWRules _rules;
|
DWRules _rules;
|
||||||
|
ulong _size;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
this(const JSONValue watchJson)
|
this(const JSONValue watchJson)
|
||||||
{
|
{
|
||||||
_path = watchJson.jget!string("path", JSONType.STRING);
|
_path = watchJson.jget!string("path", JSONType.STRING);
|
||||||
|
_size = watchJson.jgetOptional!long("size", JSONType.INTEGER);
|
||||||
auto rj = watchJson.jgetOptional!JSONValue("rules", JSONType.OBJECT);
|
auto rj = watchJson.jgetOptional!JSONValue("rules", JSONType.OBJECT);
|
||||||
_rules = new DWRules(rj);
|
_rules = new DWRules(rj);
|
||||||
}
|
}
|
||||||
|
|
@ -92,6 +94,11 @@ public:
|
||||||
return _path;
|
return _path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@property ulong size() const
|
||||||
|
{
|
||||||
|
return _size;
|
||||||
|
}
|
||||||
|
|
||||||
@property const(DWRules) rules() const
|
@property const(DWRules) rules() const
|
||||||
{
|
{
|
||||||
return _rules;
|
return _rules;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@ import std.container : RedBlackTree;
|
||||||
|
|
||||||
import wildmatch;
|
import wildmatch;
|
||||||
|
|
||||||
|
// 1.0 / 1024.0
|
||||||
|
private enum double BYTES_TO_KIB = 0.0009765625;
|
||||||
|
|
||||||
// Получить точки монтирования файловых систем
|
// Получить точки монтирования файловых систем
|
||||||
const(string)[] mountPointsFilesystem(const(string)[] skipMounts = ["/dev", "/sys", "/proc", "/run", "/tmp"]) {
|
const(string)[] mountPointsFilesystem(const(string)[] skipMounts = ["/dev", "/sys", "/proc", "/run", "/tmp"]) {
|
||||||
RedBlackTree!string mountPoints = new RedBlackTree!string();
|
RedBlackTree!string mountPoints = new RedBlackTree!string();
|
||||||
|
|
@ -102,6 +105,7 @@ struct DevIno {
|
||||||
ulong dev;
|
ulong dev;
|
||||||
ulong ino;
|
ulong ino;
|
||||||
int pid;
|
int pid;
|
||||||
|
double size;
|
||||||
|
|
||||||
bool opEquals(const DevIno rhs) const @safe nothrow {
|
bool opEquals(const DevIno rhs) const @safe nothrow {
|
||||||
return dev == rhs.dev && ino == rhs.ino && pid == rhs.pid;
|
return dev == rhs.dev && ino == rhs.ino && pid == rhs.pid;
|
||||||
|
|
@ -110,12 +114,16 @@ struct DevIno {
|
||||||
size_t toHash() const @safe nothrow {
|
size_t toHash() const @safe nothrow {
|
||||||
return (dev * 1_315_423_911UL) ^ (ino * 2_654_435_761UL) ^ (cast(size_t) pid);
|
return (dev * 1_315_423_911UL) ^ (ino * 2_654_435_761UL) ^ (cast(size_t) pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double getSize() const @safe nothrow {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getDevIno(int fd, out DevIno di, int pid) {
|
bool getDevIno(int fd, out DevIno di, int pid) {
|
||||||
stat_t st;
|
stat_t st;
|
||||||
if (fstat(fd, &st) != 0) return false;
|
if (fstat(fd, &st) != 0) return false;
|
||||||
di = DevIno(cast(ulong) st.st_dev, cast(ulong) st.st_ino, pid);
|
di = DevIno(cast(ulong) st.st_dev, cast(ulong) st.st_ino, pid, cast(long) st.st_size * BYTES_TO_KIB);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue