[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25333 - in gnunet/src: include util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25333 - in gnunet/src: include util |
Date: |
Sun, 9 Dec 2012 16:38:56 +0100 |
Author: grothoff
Date: 2012-12-09 16:38:55 +0100 (Sun, 09 Dec 2012)
New Revision: 25333
Modified:
gnunet/src/include/gnunet_disk_lib.h
gnunet/src/util/crypto_rsa.c
gnunet/src/util/disk.c
Log:
adding GNUNET_DISK_file_backup function; fixing #2646
Modified: gnunet/src/include/gnunet_disk_lib.h
===================================================================
--- gnunet/src/include/gnunet_disk_lib.h 2012-12-08 22:10:08 UTC (rev
25332)
+++ gnunet/src/include/gnunet_disk_lib.h 2012-12-09 15:38:55 UTC (rev
25333)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009 Christian Grothoff (and
other contributing authors)
+ (C) 2001-2012 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -17,10 +17,10 @@
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
-
/**
* @file include/gnunet_disk_lib.h
* @brief disk IO apis
+ * @author Christian Grothoff
*/
#ifndef GNUNET_DISK_LIB_H
#define GNUNET_DISK_LIB_H
@@ -85,8 +85,7 @@
*/
int fd;
-#endif /*
- */
+#endif
};
@@ -113,39 +112,39 @@
enum GNUNET_DISK_OpenFlags
{
- /**
- * Open the file for reading
- */
+ /**
+ * Open the file for reading
+ */
GNUNET_DISK_OPEN_READ = 1,
- /**
- * Open the file for writing
- */
+ /**
+ * Open the file for writing
+ */
GNUNET_DISK_OPEN_WRITE = 2,
- /**
- * Open the file for both reading and writing
- */
+ /**
+ * Open the file for both reading and writing
+ */
GNUNET_DISK_OPEN_READWRITE = 3,
- /**
- * Fail if file already exists
- */
+ /**
+ * Fail if file already exists
+ */
GNUNET_DISK_OPEN_FAILIFEXISTS = 4,
- /**
- * Truncate file if it exists
- */
+ /**
+ * Truncate file if it exists
+ */
GNUNET_DISK_OPEN_TRUNCATE = 8,
- /**
- * Create file if it doesn't exist
- */
+ /**
+ * Create file if it doesn't exist
+ */
GNUNET_DISK_OPEN_CREATE = 16,
- /**
- * Append to the file
- */
+ /**
+ * Append to the file
+ */
GNUNET_DISK_OPEN_APPEND = 32
};
@@ -154,18 +153,19 @@
*/
enum GNUNET_DISK_MapType
{
- /**
- * Read-only memory map.
- */
+ /**
+ * Read-only memory map.
+ */
GNUNET_DISK_MAP_TYPE_READ = 1,
+
+ /**
+ * Write-able memory map.
+ */
+ GNUNET_DISK_MAP_TYPE_WRITE = 2,
- /**
- * Write-able memory map.
- */
- GNUNET_DISK_MAP_TYPE_WRITE = 2,
- /**
- * Read-write memory map.
- */
+ /**
+ * Read-write memory map.
+ */
GNUNET_DISK_MAP_TYPE_READWRITE = 3
};
@@ -175,54 +175,54 @@
*/
enum GNUNET_DISK_AccessPermissions
{
- /**
- * Nobody is allowed to do anything to the file.
- */
+ /**
+ * Nobody is allowed to do anything to the file.
+ */
GNUNET_DISK_PERM_NONE = 0,
- /**
- * Owner can read.
- */
+ /**
+ * Owner can read.
+ */
GNUNET_DISK_PERM_USER_READ = 1,
- /**
- * Owner can write.
- */
+ /**
+ * Owner can write.
+ */
GNUNET_DISK_PERM_USER_WRITE = 2,
- /**
- * Owner can execute.
- */
+ /**
+ * Owner can execute.
+ */
GNUNET_DISK_PERM_USER_EXEC = 4,
- /**
- * Group can read.
- */
+ /**
+ * Group can read.
+ */
GNUNET_DISK_PERM_GROUP_READ = 8,
- /**
- * Group can write.
- */
+ /**
+ * Group can write.
+ */
GNUNET_DISK_PERM_GROUP_WRITE = 16,
- /**
- * Group can execute.
- */
+ /**
+ * Group can execute.
+ */
GNUNET_DISK_PERM_GROUP_EXEC = 32,
- /**
- * Everybody can read.
- */
+ /**
+ * Everybody can read.
+ */
GNUNET_DISK_PERM_OTHER_READ = 64,
- /**
- * Everybody can write.
- */
+ /**
+ * Everybody can write.
+ */
GNUNET_DISK_PERM_OTHER_WRITE = 128,
- /**
- * Everybody can execute.
- */
+ /**
+ * Everybody can execute.
+ */
GNUNET_DISK_PERM_OTHER_EXEC = 256
};
@@ -233,19 +233,19 @@
*/
enum GNUNET_DISK_Seek
{
- /**
- * Seek an absolute position (from the start of the file).
- */
+ /**
+ * Seek an absolute position (from the start of the file).
+ */
GNUNET_DISK_SEEK_SET = 0,
- /**
- * Seek a relative position (from the current offset).
- */
+ /**
+ * Seek a relative position (from the current offset).
+ */
GNUNET_DISK_SEEK_CUR = 1,
- /**
- * Seek an absolute position from the end of the file.
- */
+ /**
+ * Seek an absolute position from the end of the file.
+ */
GNUNET_DISK_SEEK_END = 2
};
@@ -255,14 +255,14 @@
*/
enum GNUNET_DISK_PipeEnd
{
- /**
- * The reading-end of a pipe.
- */
+ /**
+ * The reading-end of a pipe.
+ */
GNUNET_DISK_PIPE_END_READ = 0,
- /**
- * The writing-end of a pipe.
- */
+ /**
+ * The writing-end of a pipe.
+ */
GNUNET_DISK_PIPE_END_WRITE = 1
};
@@ -301,6 +301,17 @@
/**
+ * Move a file out of the way (create a backup) by
+ * renaming it to "orig.NUM~" where NUM is the smallest
+ * number that is not used yet.
+ *
+ * @param fil name of the file to back up
+ */
+void
+GNUNET_DISK_file_backup (const char *fil);
+
+
+/**
* Move the read/write pointer in a file
* @param h handle of an open file
* @param offset position to move to
Modified: gnunet/src/util/crypto_rsa.c
===================================================================
--- gnunet/src/util/crypto_rsa.c 2012-12-08 22:10:08 UTC (rev 25332)
+++ gnunet/src/util/crypto_rsa.c 2012-12-09 15:38:55 UTC (rev 25333)
@@ -641,12 +641,11 @@
if (fs > UINT16_MAX)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("File `%s' does not contain a valid private key (too long, %llu
bytes). Deleting it.\n"),
+ _("File `%s' does not contain a valid private key (too long, %llu
bytes). Renaming it.\n"),
filename,
(unsigned long long) fs);
GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fd));
- if (0 != UNLINK (filename))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
+ GNUNET_DISK_file_backup (filename);
return NULL;
}
@@ -662,8 +661,7 @@
filename,
(unsigned long long) fs);
GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fd));
- if (0 != UNLINK (filename))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
+ GNUNET_DISK_file_backup (filename);
GNUNET_free (enc);
return NULL;
}
@@ -857,10 +855,7 @@
LOG (GNUNET_ERROR_TYPE_ERROR,
_("File `%s' does not contain a valid private key. Deleting it.\n"),
filename);
- if (0 != UNLINK (filename))
- {
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
- }
+ GNUNET_DISK_file_backup (filename);
}
GNUNET_free (enc);
if (GNUNET_YES !=
Modified: gnunet/src/util/disk.c
===================================================================
--- gnunet/src/util/disk.c 2012-12-08 22:10:08 UTC (rev 25332)
+++ gnunet/src/util/disk.c 2012-12-09 15:38:55 UTC (rev 25333)
@@ -495,6 +495,38 @@
/**
+ * Move a file out of the way (create a backup) by
+ * renaming it to "orig.NUM~" where NUM is the smallest
+ * number that is not used yet.
+ *
+ * @param fil name of the file to back up
+ */
+void
+GNUNET_DISK_file_backup (const char *fil)
+{
+ size_t slen;
+ char *target;
+ unsigned int num;
+
+ slen = strlen (fil) + 20;
+ target = GNUNET_malloc (slen);
+ num = 0;
+ do
+ {
+ GNUNET_snprintf (target, slen,
+ "%s.%u~",
+ fil,
+ num++);
+ } while (0 == access (target, F_OK));
+ if (0 != rename (fil, target))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "rename",
+ fil);
+ GNUNET_free (target);
+}
+
+
+/**
* Create an (empty) temporary file on disk. If the given name is not
* an absolute path, the current 'TMPDIR' will be prepended. In any case,
* 6 random characters will be appended to the name to create a unique
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25333 - in gnunet/src: include util,
gnunet <=