Discussion:
[PATCH] added checks for locked dump directory to dd_* functions, closes #133 Signed-off-by: Petr Kubat <pkubat-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Petr Kubat
2013-08-20 12:39:02 UTC
Permalink
---
src/lib/dump_dir.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
index c1037b3..c3f5c57 100644
--- a/src/lib/dump_dir.c
+++ b/src/lib/dump_dir.c
@@ -811,6 +811,12 @@ static int delete_file_dir(const char *dir, bool skip_lock_file)

int dd_delete(struct dump_dir *dd)
{
+ if (!dd->locked)
+ {
+ error_msg("dump_dir is not locked for writing");
+ return -1;
+ }
+
int r = delete_file_dir(dd->dd_dirname, /*skip_lock_file:*/ true);
dd->locked = 0; /* delete_file_dir already removed .lock */
dd_close(dd);
@@ -1214,6 +1220,12 @@ report_result_t *find_in_reported_to(struct dump_dir *dd, const char *prefix)

int dd_rename(struct dump_dir *dd, const char *new_path)
{
+ if (!dd->locked)
+ {
+ error_msg("dump_dir is not locked for writing");
+ return -1;
+ }
+
int res = rename(dd->dd_dirname, new_path);
if (res == 0)
{
@@ -1221,6 +1233,7 @@ int dd_rename(struct dump_dir *dd, const char *new_path)
dd->dd_dirname = rm_trailing_slashes(new_path);
}
return res;
+
}

/* Utility function */
--
1.8.3.1
Jiri Moskovcak
2013-08-21 14:42:41 UTC
Permalink
Post by Petr Kubat
---
src/lib/dump_dir.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
index c1037b3..c3f5c57 100644
--- a/src/lib/dump_dir.c
+++ b/src/lib/dump_dir.c
@@ -811,6 +811,12 @@ static int delete_file_dir(const char *dir, bool skip_lock_file)
int dd_delete(struct dump_dir *dd)
{
+ if (!dd->locked)
+ {
+ error_msg("dump_dir is not locked for writing");
+ return -1;
- please change the error message so it's clear where it's coming from,
now we have the same msg on 3 places
- e.g: error_msg("can't delete unlocked problem directory '%s'",
dd->dd_dirname)
Post by Petr Kubat
+ }
+
int r = delete_file_dir(dd->dd_dirname, /*skip_lock_file:*/ true);
dd->locked = 0; /* delete_file_dir already removed .lock */
dd_close(dd);
@@ -1214,6 +1220,12 @@ report_result_t *find_in_reported_to(struct dump_dir *dd, const char *prefix)
int dd_rename(struct dump_dir *dd, const char *new_path)
{
+ if (!dd->locked)
+ {
+ error_msg("dump_dir is not locked for writing");
+ return -1;
- same here
Post by Petr Kubat
+ }
+
int res = rename(dd->dd_dirname, new_path);
if (res == 0)
{
@@ -1221,6 +1233,7 @@ int dd_rename(struct dump_dir *dd, const char *new_path)
dd->dd_dirname = rm_trailing_slashes(new_path);
}
return res;
+
}
/* Utility function */
Petr Kubat
2013-08-22 11:34:21 UTC
Permalink
Signed-off-by: Petr Kubat <pkubat-H+wXaHxf7aLQT0dZR+***@public.gmane.org>
---
src/lib/dump_dir.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
index 31adedf..4bb23ba 100644
--- a/src/lib/dump_dir.c
+++ b/src/lib/dump_dir.c
@@ -832,6 +832,12 @@ static int delete_file_dir(const char *dir, bool skip_lock_file)

int dd_delete(struct dump_dir *dd)
{
+ if (!dd->locked)
+ {
+ error_msg("unlocked problem directory %s cannot be deleted", dd->dd_dirname);
+ return -1;
+ }
+
int r = delete_file_dir(dd->dd_dirname, /*skip_lock_file:*/ true);
dd->locked = 0; /* delete_file_dir already removed .lock */
dd_close(dd);
@@ -1235,6 +1241,12 @@ report_result_t *find_in_reported_to(struct dump_dir *dd, const char *prefix)

int dd_rename(struct dump_dir *dd, const char *new_path)
{
+ if (!dd->locked)
+ {
+ error_msg("unlocked problem directory %s cannot be renamed", dd->dd_dirname);
+ return -1;
+ }
+
int res = rename(dd->dd_dirname, new_path);
if (res == 0)
{
--
1.7.11.7
Jiri Moskovcak
2013-09-03 13:35:12 UTC
Permalink
- pushed (with fixed whitespace errors), thx
Post by Petr Kubat
---
src/lib/dump_dir.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
index 31adedf..4bb23ba 100644
--- a/src/lib/dump_dir.c
+++ b/src/lib/dump_dir.c
@@ -832,6 +832,12 @@ static int delete_file_dir(const char *dir, bool skip_lock_file)
int dd_delete(struct dump_dir *dd)
{
+ if (!dd->locked)
+ {
+ error_msg("unlocked problem directory %s cannot be deleted", dd->dd_dirname);
+ return -1;
+ }
+
int r = delete_file_dir(dd->dd_dirname, /*skip_lock_file:*/ true);
dd->locked = 0; /* delete_file_dir already removed .lock */
dd_close(dd);
@@ -1235,6 +1241,12 @@ report_result_t *find_in_reported_to(struct dump_dir *dd, const char *prefix)
int dd_rename(struct dump_dir *dd, const char *new_path)
{
+ if (!dd->locked)
+ {
+ error_msg("unlocked problem directory %s cannot be renamed", dd->dd_dirname);
+ return -1;
+ }
+
int res = rename(dd->dd_dirname, new_path);
if (res == 0)
{
Jiri Moskovcak
2013-09-05 09:14:05 UTC
Permalink
- pushed, thx
Post by Petr Kubat
---
src/lib/dump_dir.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
index 31adedf..4bb23ba 100644
--- a/src/lib/dump_dir.c
+++ b/src/lib/dump_dir.c
@@ -832,6 +832,12 @@ static int delete_file_dir(const char *dir, bool skip_lock_file)
int dd_delete(struct dump_dir *dd)
{
+ if (!dd->locked)
+ {
+ error_msg("unlocked problem directory %s cannot be deleted", dd->dd_dirname);
+ return -1;
+ }
+
int r = delete_file_dir(dd->dd_dirname, /*skip_lock_file:*/ true);
dd->locked = 0; /* delete_file_dir already removed .lock */
dd_close(dd);
@@ -1235,6 +1241,12 @@ report_result_t *find_in_reported_to(struct dump_dir *dd, const char *prefix)
int dd_rename(struct dump_dir *dd, const char *new_path)
{
+ if (!dd->locked)
+ {
+ error_msg("unlocked problem directory %s cannot be renamed", dd->dd_dirname);
+ return -1;
+ }
+
int res = rename(dd->dd_dirname, new_path);
if (res == 0)
{
Loading...