[Openvas-commits] r3252 - in trunk/openvas-client: . src/util
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed May 6 11:53:05 CEST 2009
Author: felix
Date: 2009-05-06 11:53:04 +0200 (Wed, 06 May 2009)
New Revision: 3252
Modified:
trunk/openvas-client/ChangeLog
trunk/openvas-client/src/util/file_utils.c
trunk/openvas-client/src/util/file_utils.h
Log:
* src/util/file_utils.c, src/util/file_utils.h (file_utils_rmdir_rf):
New (copied from openvas-config-manager/src/openvascd.c).
- Diese und die folgenden Zeilen werden ignoriert --
M ChangeLog
M src/util/file_utils.c
M src/util/file_utils.h
Modified: trunk/openvas-client/ChangeLog
===================================================================
--- trunk/openvas-client/ChangeLog 2009-05-06 09:43:52 UTC (rev 3251)
+++ trunk/openvas-client/ChangeLog 2009-05-06 09:53:04 UTC (rev 3252)
@@ -1,5 +1,10 @@
2009-05-06 Felix Wolfsteller <felix.wolfsteller at intevation.de>
+ * src/util/file_utils.c, src/util/file_utils.h (file_utils_rmdir_rf):
+ New (copied from openvas-config-manager/src/openvascd.c).
+
+2009-05-06 Felix Wolfsteller <felix.wolfsteller at intevation.de>
+
* nessus/prefs_dialog/prefs_dialog.c: Collapsed comments, minor
reformatting.
Modified: trunk/openvas-client/src/util/file_utils.c
===================================================================
--- trunk/openvas-client/src/util/file_utils.c 2009-05-06 09:43:52 UTC (rev 3251)
+++ trunk/openvas-client/src/util/file_utils.c 2009-05-06 09:53:04 UTC (rev 3252)
@@ -4,6 +4,7 @@
*
* Authors:
* Felix Wolfsteller <felix.wolfsteller at intevation.de>
+ * Michael Wiegand <michael.wiegand at intevation.de>
*
* Copyright:
* Copyright (C) 2009 Intevation GmbH
@@ -45,7 +46,59 @@
* be moved when the openvas-module boundaries got a more clear definition.
*/
+
/**
+ * @brief Recursively removes files and directories.
+ *
+ * This function will recursively call itself to delete a path and any
+ * contents of this path.
+ *
+ * @param pathname The name of the file to be deleted from the filesystem.
+ *
+ * @return 0 if the name was successfully deleted, -1 if an error occurred.
+ * Please note that errno is currently not guaranteed to contain the correct
+ * value if -1 is returned.
+ */
+int
+file_utils_rmdir_rf (const gchar * pathname)
+{
+ if (check_is_dir (pathname) == 1)
+ {
+ GError *error = NULL;
+ GDir *directory = g_dir_open (pathname, 0, &error);
+
+ if (directory == NULL)
+ {
+ g_warning ("g_dir_open(%s) failed - %s\n", pathname, error->message);
+ g_error_free (error);
+ // errno should be set when we return -1 to maintain remove()
+ // compatibility.
+ return -1;
+ }
+ else
+ {
+ int ret = 0;
+ const gchar *entry = NULL;
+
+ while ((entry = g_dir_read_name (directory)) && (ret == 0))
+ {
+ ret = file_utils_rmdir_rf (g_build_filename (pathname, entry, NULL));
+ if (ret != 0)
+ {
+ g_warning ("Failed to remove %s from %s!", entry, pathname);
+ g_dir_close (directory);
+ return ret;
+ }
+ }
+ g_dir_close (directory);
+ }
+ }
+
+ return g_remove (pathname);
+}
+
+
+/**
* @brief Reads contents from a source file into a destination file.
*
* The source file is read into memory, so it is inefficient and likely to fail
Modified: trunk/openvas-client/src/util/file_utils.h
===================================================================
--- trunk/openvas-client/src/util/file_utils.h 2009-05-06 09:43:52 UTC (rev 3251)
+++ trunk/openvas-client/src/util/file_utils.h 2009-05-06 09:53:04 UTC (rev 3252)
@@ -43,5 +43,6 @@
const gchar* dest_file);
gboolean file_utils_move_file (const gchar* source_file,
const gchar* dest_file);
+gboolean file_utils_rmdir_rf (const char* dir);
#endif
More information about the Openvas-commits
mailing list