mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-26 16:43:27 +01:00
Store temp data in same directory as original file
This commit is contained in:
parent
93a73cbef2
commit
14a8bdb874
@ -125,7 +125,13 @@ void kill_friendlist(void)
|
|||||||
realloc_friends(0);
|
realloc_friends(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEMP_BLOCKLIST_SAVE_NAME "toxic_blocklist.tmp"
|
/* Saves the blocklist to path. If there are no items in the blocklist the
|
||||||
|
* empty file will be removed.
|
||||||
|
*
|
||||||
|
* Returns 0 if stored successfully.
|
||||||
|
* Returns -1 on failure.
|
||||||
|
*/
|
||||||
|
#define TEMP_BLOCKLIST_EXT ".tmp"
|
||||||
static int save_blocklist(char *path)
|
static int save_blocklist(char *path)
|
||||||
{
|
{
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
@ -165,19 +171,23 @@ static int save_blocklist(char *path)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *fp = fopen(TEMP_BLOCKLIST_SAVE_NAME, "wb");
|
char temp_path[strlen(path) + strlen(TEMP_BLOCKLIST_EXT) + 1];
|
||||||
|
snprintf(temp_path, sizeof(temp_path), "%s%s", path, TEMP_BLOCKLIST_EXT);
|
||||||
|
|
||||||
|
FILE *fp = fopen(temp_path, "wb");
|
||||||
|
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (fwrite(data, len, 1, fp) != 1) {
|
if (fwrite(data, len, 1, fp) != 1) {
|
||||||
|
fprintf(stderr, "Failed to write blocklist data.\n");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
if (rename(TEMP_BLOCKLIST_SAVE_NAME, path) != 0)
|
if (rename(temp_path, path) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
13
src/toxic.c
13
src/toxic.c
@ -537,18 +537,21 @@ static void first_time_encrypt(const char *msg)
|
|||||||
system("clear");
|
system("clear");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Store Tox profile data to given location
|
/* Store Tox profile data to path.
|
||||||
*
|
*
|
||||||
* Return 0 if stored successfully.
|
* Return 0 if stored successfully.
|
||||||
* Return -1 on error.
|
* Return -1 on error.
|
||||||
*/
|
*/
|
||||||
#define TEMP_PROFILE_SAVE_NAME "toxic_profile.tmp"
|
#define TEMP_PROFILE_EXT ".tmp"
|
||||||
int store_data(Tox *m, const char *path)
|
int store_data(Tox *m, const char *path)
|
||||||
{
|
{
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
FILE *fp = fopen(TEMP_PROFILE_SAVE_NAME, "wb");
|
char temp_path[strlen(path) + strlen(TEMP_PROFILE_EXT) + 1];
|
||||||
|
snprintf(temp_path, sizeof(temp_path), "%s%s", path, TEMP_PROFILE_EXT);
|
||||||
|
|
||||||
|
FILE *fp = fopen(temp_path, "wb");
|
||||||
|
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
@ -573,11 +576,13 @@ int store_data(Tox *m, const char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fwrite(enc_data, enc_len, 1, fp) != 1) {
|
if (fwrite(enc_data, enc_len, 1, fp) != 1) {
|
||||||
|
fprintf(stderr, "Failed to write profile data.\n");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else { /* data will not be encrypted */
|
} else { /* data will not be encrypted */
|
||||||
if (fwrite(data, data_len, 1, fp) != 1) {
|
if (fwrite(data, data_len, 1, fp) != 1) {
|
||||||
|
fprintf(stderr, "Failed to write profile data.\n");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -585,7 +590,7 @@ int store_data(Tox *m, const char *path)
|
|||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
if (rename(TEMP_PROFILE_SAVE_NAME, path) != 0)
|
if (rename(temp_path, path) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user