commit - 4de8e2182c447e4635fb977a2b95976b8f82e5d4
commit + 7c0529df50f0f6a59fd45d1a62fe9f45f52215b8
blob - d1ea8281d1fc03b0c5f151e568c6df0fb4cf7d55
blob + 41e8135d455a15a2c78a78cad818b2e95e7d23c9
--- src/addressbook.c
+++ src/addressbook.c
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include <string.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include "main.h"
/* Use new address book index. */
if ( !is_dir_exist(indexdir) ) {
- if ( make_dir(indexdir) < 0 ) {
+ if (mkdir(indexdir, 0700) < 0 ) {
addrindex_set_file_path( addrIndex, get_rc_dir() );
g_warning("couldn't create dir '%s'", indexdir);
} else {
blob - 1c51fec62c0b194f3e19a2e15eed3d7d52edb132
blob + a9cc1b4061280a4e2824542b0e0da097d2e064c3
--- src/common/file-utils.c
+++ src/common/file-utils.c
if (fclose(outfp) == EOF) {
goto unlinkout;
}
-
- if (move_file(out, file, TRUE) < 0)
+ if (rename(out, file) < 0)
goto unlinkout;
g_free(out);
return -1;
}
- if (change_file_mode_rw(dest_fp, dest) < 0) {
- FILE_OP_ERROR(dest, "chmod");
- g_warning("can't change file mode: %s", dest);
- }
-
while ((n_read = fread(buf, sizeof(gchar), sizeof(buf), src_fp)) > 0) {
if (n_read < sizeof(buf) && ferror(src_fp))
break;
}
if (is_file_exist(dest)) {
dest_bak = g_strconcat(dest, ".bak", NULL);
- if (rename_force(dest, dest_bak) < 0) {
- FILE_OP_ERROR(dest, "rename");
+ if (rename(dest, dest_bak) < 0) {
+ warn("rename %s to %s", dest, dest_bak);
fclose(src_fp);
g_free(dest_bak);
return -1;
FILE_OP_ERROR(dest, "g_fopen");
fclose(src_fp);
if (dest_bak) {
- if (rename_force(dest_bak, dest) < 0)
+ if (rename(dest_bak, dest) < 0)
FILE_OP_ERROR(dest_bak, "rename");
g_free(dest_bak);
}
return -1;
}
- if (change_file_mode_rw(dest_fp, dest) < 0) {
- FILE_OP_ERROR(dest, "chmod");
- g_warning("can't change file mode: %s", dest);
- }
-
while ((n_read = fread(buf, sizeof(gchar), sizeof(buf), src_fp)) > 0) {
if (n_read < sizeof(buf) && ferror(src_fp))
break;
if (unlink(dest) < 0)
FILE_OP_ERROR(dest, "unlink");
if (dest_bak) {
- if (rename_force(dest_bak, dest) < 0)
+ if (rename(dest_bak, dest) < 0)
FILE_OP_ERROR(dest_bak, "rename");
g_free(dest_bak);
}
if (unlink(dest) < 0)
FILE_OP_ERROR(dest, "unlink");
if (dest_bak) {
- if (rename_force(dest_bak, dest) < 0)
+ if (rename(dest_bak, dest) < 0)
FILE_OP_ERROR(dest_bak, "rename");
g_free(dest_bak);
}
return 0;
}
-gint move_file(const gchar *src, const gchar *dest, gboolean overwrite)
-{
- if (overwrite == FALSE && is_file_exist(dest)) {
- g_warning("move_file(): file %s already exists", dest);
- return -1;
- }
-
- if (rename_force(src, dest) == 0) return 0;
-
- if (EXDEV != errno) {
- FILE_OP_ERROR(src, "rename");
- return -1;
- }
-
- if (copy_file(src, dest, FALSE) < 0) return -1;
-
- unlink(src);
-
- return 0;
-}
-
gint copy_file_part_to_fp(FILE *fp, off_t offset, size_t length, FILE *dest_fp)
{
gint n_read;
return -1;
}
- if (change_file_mode_rw(dest_fp, dest) < 0) {
- FILE_OP_ERROR(dest, "chmod");
- g_warning("can't change file mode: %s", dest);
- }
-
if (copy_file_part_to_fp(fp, offset, length, dest_fp) < 0)
err = TRUE;
return -1;
}
- if (change_file_mode_rw(dest_fp, dest) < 0) {
- FILE_OP_ERROR(dest, "chmod");
- g_warning("can't change file mode: %s", dest);
- }
-
while (fgets(buf, sizeof(buf), src_fp) != NULL) {
gint r = 0;
return 0;
}
-gint canonicalize_file_replace(const gchar *file)
-{
- gchar *tmp_file;
-
- tmp_file = get_tmp_file();
-
- if (canonicalize_file(file, tmp_file) < 0) {
- g_free(tmp_file);
- return -1;
- }
-
- if (move_file(tmp_file, file, TRUE) < 0) {
- g_warning("can't replace file: %s", file);
- unlink(tmp_file);
- g_free(tmp_file);
- return -1;
- }
-
- g_free(tmp_file);
- return 0;
-}
-
-
gint str_write_to_file(const gchar *str, char *file)
{
if (strlen(str) == 0)
return file_read_stream_to_str_full(fp, TRUE);
}
-gchar *file_read_to_str_no_recode(const gchar *file)
-{
- return file_read_to_str_full(file, FALSE);
-}
-gchar *file_read_stream_to_str_no_recode(FILE *fp)
-{
- return file_read_stream_to_str_full(fp, FALSE);
-}
-
-gint rename_force(const gchar *oldpath, const gchar *newpath)
-{
-#ifndef G_OS_UNIX
- if (!is_file_entry_exist(oldpath)) {
- errno = ENOENT;
- return -1;
- }
- if (is_file_exist(newpath)) {
- if (unlink(newpath) < 0)
- FILE_OP_ERROR(newpath, "unlink");
- }
-#endif
- return g_rename(oldpath, newpath);
-}
-
gint copy_dir(const gchar *src, const gchar *dst)
{
GDir *dir;
const gchar *name;
if ((dir = g_dir_open(src, 0, NULL)) == NULL) {
- g_warning("failed to open directory: %s", src);
+ warn("open %s", src);
return -1;
}
- if (make_dir(dst) < 0) {
+ if (mkdir(dst, 0700) < 0) {
g_dir_close(dir);
return -1;
}
return 0;
}
-gint change_file_mode_rw(FILE *fp, const gchar *file)
-{
- return fchmod(fileno(fp), S_IRUSR|S_IWUSR);
-}
-
FILE *my_tmpfile(void)
{
const gchar suffix[] = ".XXXXXX";
blob - 7415f849ff040114ad012afab9c343361d9c84f7
blob + 7153206ffbfa030fa44259a2ef2f66e3db64c03b
--- src/common/file-utils.h
+++ src/common/file-utils.h
gint copy_file (const gchar *src,
const gchar *dest,
gboolean keep_backup);
-gint move_file (const gchar *src,
- const gchar *dest,
- gboolean overwrite);
gint copy_file_part_to_fp (FILE *fp,
off_t offset,
size_t length,
const gchar *dest);
gint canonicalize_file (const gchar *src,
const gchar *dest);
-gint canonicalize_file_replace (const gchar *file);
gchar *file_read_to_str (const gchar *file);
-gchar *file_read_to_str_no_recode(const gchar *file);
gchar *file_read_stream_to_str (FILE *fp);
-gchar *file_read_stream_to_str_no_recode(FILE *fp);
-gint rename_force (const gchar *oldpath,
- const gchar *newpath);
gint copy_dir (const gchar *src,
const gchar *dest);
-gint change_file_mode_rw (FILE *fp,
- const gchar *file);
FILE *my_tmpfile (void);
FILE *get_tmpfile_in_dir (const gchar *dir,
gchar **filename);
blob - 12b624cdbace2d76e2d17d2f7e9c92c21cf0427a
blob + 2d84f172f2b6f44f81be97dfd91490fa21eeaf39
--- src/common/log.c
+++ src/common/log.c
return;
}
- if (change_file_mode_rw(log_fp[instance], fullname) < 0) {
- FILE_OP_ERROR(fullname, "chmod");
- g_warning("can't change file mode: %s", fullname);
- }
-
log_filename[instance] = g_strdup(fullname);
log_size[instance] = 0;
g_free(fullname);
blob - 06f3b712bcdb551dc96c7c9529b95d5662710531
blob + e805e85ebb84a3a47032fb0e819cc85cf299cef9
--- src/common/prefs.c
+++ src/common/prefs.c
*/
#include <stdio.h>
+#include <string.h>
#include "defs.h"
#include "prefs.h"
#include "utils.h"
-#include "file-utils.h"
static gboolean prefs_is_readonly (const gchar *path);
-/*!
- *\brief Open preferences file for reading
- *
- *\param path Filename with path of preferences file to read
- *
- *\return PrefFile * preferences file struct
+/*
+ * Open preferences file for writing
+ * Prefs are written to a temp file: Call prefs_file_close()
+ * to rename this to the final filename
*/
-PrefFile *prefs_read_open(const gchar *path)
-{
- PrefFile *pfile;
- FILE *fp;
-
- cm_return_val_if_fail(path != NULL, NULL);
-
- if ((fp = g_fopen(path, "rb")) == NULL) {
- FILE_OP_ERROR(path, "g_fopen");
- return NULL;
- }
-
- pfile = g_new(PrefFile, 1);
- pfile->fp = fp;
- pfile->orig_fp = NULL;
- pfile->path = g_strdup(path);
- pfile->writing = FALSE;
-
- return pfile;
-}
-
-/*!
- *\brief Open preferences file for writing
- * Prefs are written to a temp file: Call prefs_file_close()
- * to rename this to the final filename
- *
- *\param path Filename with path of preferences file to write
- *
- *\return PrefFile * preferences file struct
- */
PrefFile *prefs_write_open(const gchar *path)
{
- PrefFile *pfile;
- gchar *tmppath;
FILE *fp;
-
- cm_return_val_if_fail(path != NULL, NULL);
-
- if (prefs_is_readonly(path)) {
- g_warning("no write permission on '%s'", path);
+ char tmp[PATH_MAX];
+ strlcpy(tmp, path, sizeof(tmp));
+ strlcat(tmp, ".tmp", sizeof(tmp));
+ if ((fp = fopen(tmp, "w")) == NULL) {
+ char msg[PATH_MAX];
+ snprintf(msg, sizeof(msg), "open %s", tmp);
+ perror(msg);
return NULL;
}
- tmppath = g_strconcat(path, ".tmp", NULL);
- if ((fp = g_fopen(tmppath, "wb")) == NULL) {
- FILE_OP_ERROR(tmppath, "g_fopen");
- g_free(tmppath);
- return NULL;
- }
-
- if (change_file_mode_rw(fp, tmppath) < 0)
- FILE_OP_ERROR(tmppath, "chmod");
-
- g_free(tmppath);
-
- pfile = g_new(PrefFile, 1);
+ PrefFile *pfile = g_new(PrefFile, 1);
pfile->fp = fp;
pfile->orig_fp = NULL;
- pfile->path = g_strdup(path);
+ pfile->path = strdup(path);
pfile->writing = TRUE;
-
return pfile;
}
return (access(path, W_OK) != 0 && access(path, F_OK) == 0);
}
-/*!
- *\brief Check if "rcfile" is in rcdir, a file and read-only
- */
gboolean prefs_rc_is_readonly(const gchar * rcfile)
{
- gboolean result;
- gchar * rcpath;
-
- if (rcfile == NULL)
- return TRUE;
-
- rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, rcfile, NULL);
- result = prefs_is_readonly(rcpath);
- g_free(rcpath);
-
- return result;
+ char path[PATH_MAX];
+ snprintf(path, sizeof(path), "%s/%s", get_rc_dir(), rcfile);
+ return prefs_is_readonly(path);
}
/*!
blob - 3feddda7f783f3321143b789b9233d6c9d6c7ad2
blob + 129891cbaf3d42b37eb9e4fc426540222b2a5b6c
--- src/common/prefs.h
+++ src/common/prefs.h
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ *
*/
#ifndef PREFS_H
gboolean writing;
};
-PrefFile *prefs_read_open (const gchar *path);
PrefFile *prefs_write_open (const gchar *path);
gint prefs_file_close (PrefFile *pfile);
gint prefs_file_close_revert (PrefFile *pfile);
blob - a74762ffa52c911c0e5863f74aca8758d7a4f31b
blob + 03ef317d0def9ac573b848005d487a50c195d5cb
--- src/common/ssl_certificate.c
+++ src/common/ssl_certificate.c
gchar *old = get_certificate_path(host, buf, NULL);
gchar *new = get_certificate_path(host, buf, fingerprint);
if (strcmp(old, new))
- move_file(old, new, TRUE);
+ rename(old, new);
g_free(old);
g_free(new);
}
blob - de62e33401dca583a41b80309db4b0ddc94d6b4c
blob + dbcb4b1b451fa139e7586d611da8ac698151f653
--- src/common/utils.c
+++ src/common/utils.c
return 0;
}
-gint make_dir(const gchar *dir)
-{
- if (g_mkdir(dir, S_IRWXU) < 0) {
- FILE_OP_ERROR(dir, "mkdir");
- return -1;
- }
- if (g_chmod(dir, S_IRWXU) < 0)
- FILE_OP_ERROR(dir, "chmod");
-
- return 0;
-}
-
gint make_dir_hier(const gchar *dir)
{
gchar *parent_dir;
parent_dir = g_strndup(dir, p - dir);
if (*parent_dir != '\0') {
if (!is_dir_exist(parent_dir)) {
- if (make_dir(parent_dir) < 0) {
+ if (mkdir(parent_dir, 0700) < 0) {
g_free(parent_dir);
return -1;
}
g_free(parent_dir);
}
- if (!is_dir_exist(dir)) {
- if (make_dir(dir) < 0)
- return -1;
- }
-
+ if (mkdir(dir, 0700) < 0 && errno != EEXIST)
+ return -1;
return 0;
}
return debug_mode;
}
-#ifdef HAVE_VA_OPT
-void debug_print_real(const char *file, int line, const gchar *format, ...)
-{
- va_list args;
- gchar buf[BUFFSIZE];
- gint prefix_len;
+void debug_print_real(const gchar *format, ...) {
+ if (!debug_mode)
+ return;
- if (!debug_mode) return;
-
- prefix_len = g_snprintf(buf, sizeof(buf), "%s:%d:", debug_srcname(file), line);
-
- va_start(args, format);
- g_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, format, args);
- va_end(args);
-
- g_print("%s", buf);
-}
-#else
-void debug_print_real(const gchar *format, ...)
-{
va_list args;
gchar buf[BUFFSIZE];
- if (!debug_mode) return;
-
va_start(args, format);
g_vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
-
- g_print("%s", buf);
+ fprintf(stderr, "%s\n", buf);
}
-#endif
-
const char * debug_srcname(const char *file)
{
const char *s = strrchr (file, '/');
blob - 3f89d69e211dbc84fd5fde69c5ac885485b1c5a1
blob + 8604b46219b1585be292d6b897d8c559518322f3
--- src/common/utils.h
+++ src/common/utils.h
#define is_file_or_fifo_exist(file) file_exist(file, TRUE)
gint change_dir (const gchar *dir);
-gint make_dir (const gchar *dir);
gint make_dir_hier (const gchar *dir);
gint remove_all_files (const gchar *dir);
gint remove_numbered_files (const gchar *dir,
blob - 676a1274f89652e6fe4190634cd4eb15f65b9e4b
blob + a07a0a1a9d27d410145361e80f2eb5b528504296
--- src/compose.c
+++ src/compose.c
size_t len;
gchar *chars, *tmp;
- if ((fp = g_fopen(file, "wb")) == NULL) {
- FILE_OP_ERROR(file, "g_fopen");
+ if ((fp = fopen(file, "wb")) == NULL) {
+ warn("open %s", file);
return -1;
}
- /* chmod for security */
- if (change_file_mode_rw(fp, file) < 0) {
- FILE_OP_ERROR(file, "chmod");
- g_warning("can't change file mode");
- }
-
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
gtk_text_buffer_get_start_iter(buffer, &start);
gtk_text_buffer_get_end_iter(buffer, &end);
G_DIR_SEPARATOR, compose, (guint) rand());
debug_print("queuing to %s\n", tmp);
if ((fp = g_fopen(tmp, "w+b")) == NULL) {
- FILE_OP_ERROR(tmp, "g_fopen");
+ warn("open %s", tmp);
g_free(tmp);
return COMPOSE_QUEUE_ERROR_WITH_ERRNO;
}
- if (change_file_mode_rw(fp, tmp) < 0) {
- FILE_OP_ERROR(tmp, "chmod");
- g_warning("can't change file mode");
- }
-
/* queueing variables */
err |= (fprintf(fp, "AF:\n") < 0);
err |= (fprintf(fp, "NF:0\n") < 0);
goto warn_err;
}
- /* chmod for security unless folder chmod is set */
prefs = draft->prefs;
if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
filemode = prefs->folder_chmod;
if (filemode & S_IROTH) filemode |= S_IWOTH;
if (chmod(tmp, filemode) < 0)
FILE_OP_ERROR(tmp, "chmod");
- } else if (change_file_mode_rw(fp, tmp) < 0) {
- FILE_OP_ERROR(tmp, "chmod");
- g_warning("can't change file mode");
}
/* Save draft infos */
blob - e2eefa528a0db568c9fb1d27eb6edd40d97b8bf8
blob + aed37b1e72184630098e5bf555a469fce9dfa459
--- src/folder.c
+++ src/folder.c
Folder *folder_find_from_identifier(const gchar *identifier)
{
- gchar *str;
gchar *p;
gchar *name;
FolderClass *class;
if (*identifier != '#')
return NULL;
- Xstrdup_a(str, identifier, return NULL);
+ char str[BUFSIZ];
+ strlcpy(str, identifier, sizeof(str));
p = strchr(str, '/');
if (!p)
blob - 54f8d8687cfbd93354262b954e202faef73eba85
blob + 1c67a8e79638308787577f809c37d190b72d2371
--- src/inc.c
+++ src/inc.c
}
debug_print("Getting new messages from %s into %s...\n", mbox, dest->path);
if (copy_mbox(spool, tmp_mbox) < 0) {
+ perror("copy mbox");
flock(spool, LOCK_UN);
close(spool);
return -1;
blob - 5bd8b7b5d43bf52cc5a7a74f0d3b6569454bdbf4
blob + d7183846edf734aa24d8b61eb7456c18e519eeb8
--- src/main.c
+++ src/main.c
int main(int argc, char *argv[])
{
- gchar *userrc;
MainWindow *mainwin;
FolderView *folderview;
GdkPixbuf *icon;
if (cmd.status || cmd.status_full || cmd.search ||
cmd.cancel_receiving || cmd.cancel_sending ||
cmd.debug) {
- puts("0 Claws Mail not running.");
+ puts("Claws Mail not running");
lock_socket_remove();
return 0;
}
CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
- if (!is_dir_exist(get_rc_dir())) {
- if (copy_dir("/etc/skel/.claws-mail", get_rc_dir()) < 0) {
- if (!is_dir_exist(get_rc_dir()) && make_dir(get_rc_dir()) < 0) {
- exit(1);
- }
+ if (mkdir(get_rc_dir(), 0700) == 0) {
+ char *skel = "/etc/skel/.claws-mail";
+ if (copy_dir(skel, get_rc_dir()) < 0) {
+ err(1, "copy template config directory from %s to %s", skel, get_rc_dir());
}
}
- userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
- gtk_rc_parse(userrc);
- g_free(userrc);
-
- userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
-
+ char userrc[PATH_MAX];
+ snprintf(userrc, sizeof(userrc), "%s/%s", get_rc_dir, MENU_RC);
if (copy_file(userrc, userrc, TRUE) < 0) {
- g_warning("can't copy %s to %s.bak", userrc, userrc);
+ warn("backup %s to %s.bak", userrc, userrc);
}
gtk_accel_map_load (userrc);
- g_free(userrc);
CHDIR_RETURN_VAL_IF_FAIL(get_rc_dir(), 1);
if (mkdir(get_mail_base_dir(), 0755) < 0 && errno != EEXIST)
return sc_starting;
}
-gchar *claws_get_socket_name(void)
+char *claws_get_socket_name(void)
{
- char *dir = g_strdup_printf("%s/claws-mail", g_get_user_runtime_dir());
- struct stat sb;
- int ok = stat(dir, &sb);
- if (ok < 0 && errno != ENOENT) {
- g_print("stat %s: %s\n", dir, g_strerror(errno));
- }
- if (!is_dir_exist(dir) && make_dir(dir) < 0) {
- g_print("create %s: %s\n", dir, g_strerror(errno));
- }
- char *filename = g_strdup_printf("%s/control.sock", dir);
- g_free(dir);
-
- debug_print("Using control socket %s\n", filename);
- return filename;
+ char path[PATH_MAX];
+ snprintf(path, sizeof(path), "%s/claws-mail", g_get_user_runtime_dir());
+ if (mkdir(path, 0755) < 0 && errno != EEXIST)
+ warn("mkdir %s", path);
+ strlcat(path, "/control.sock", sizeof(path));
+ fprintf(stderr, "Using control socket %s\n", path);
+ return strdup(path);
}
static gint prohibit_duplicate_launch(int *argc, char ***argv)
static void open_compose_new(const gchar *address, GList *attach_files)
{
- gchar *addr = NULL;
-
+ // 254 + mailto:
+ char addr[261];
if (address) {
- Xstrdup_a(addr, address, return);
+ strlcpy(addr, address, sizeof(addr));
g_strstrip(addr);
}
-
compose_new(NULL, addr, attach_files);
}
blob - 7c68ad3202506f2f71f94a739a644262aad6cf40
blob + b97f118e9a897827e685b6f7850ea821c3427594
--- src/mbox.c
+++ src/mbox.c
g_free(tmp_file);
return -1;
}
- if (change_file_mode_rw(tmp_fp, tmp_file) < 0) {
- FILE_OP_ERROR(tmp_file, "chmod");
- }
empty_lines = 0;
lines = 0;
return msgs;
}
-gint copy_mbox(gint srcfd, const gchar *dest)
-{
- FILE *dest_fp;
+int copy_mbox(gint srcfd, const gchar *dest) {
ssize_t n_read;
char buf[BUFSIZ];
- gboolean err = FALSE;
- int save_errno = 0;
- if (srcfd < 0) {
+ FILE *dest_fp = fopen(dest, "w");
+ if (dest_fp == NULL) {
+ warn("open %s", dest);
return -1;
}
+ if (chmod(dest, S_IRUSR|S_IWUSR) < 0)
+ warn("chmod %s", dest);
- if ((dest_fp = g_fopen(dest, "wb")) == NULL) {
- FILE_OP_ERROR(dest, "g_fopen");
- return -1;
- }
-
- if (change_file_mode_rw(dest_fp, dest) < 0) {
- FILE_OP_ERROR(dest, "chmod");
- g_warning("can't change file mode");
- }
-
while ((n_read = read(srcfd, buf, sizeof(buf))) > 0) {
if (fwrite(buf, 1, n_read, dest_fp) < n_read) {
g_warning("writing to %s failed", dest);
return -1;
}
}
-
- if (save_errno != 0) {
- g_warning("error %d reading mbox: %s", save_errno,
- g_strerror(save_errno));
- err = TRUE;
- }
-
- if (fclose(dest_fp) == EOF) {
- FILE_OP_ERROR(dest, "fclose");
- err = TRUE;
- }
-
- if (err) {
- unlink(dest);
- return -1;
- }
-
- return 0;
+ return fclose(dest_fp);
}
gint export_list_to_mbox(GSList *mlist, const gchar *mbox)
blob - 7ee6a4e8b56b0db644c5f8461963f0a629e72882
blob + ac957d612079e8b81315b2a4ccb6a2d4d429abd4
--- src/mh.c
+++ src/mh.c
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
+#include <err.h>
#include <errno.h>
#include <time.h>
gboolean mh_scan_required(Folder *folder, FolderItem *item)
{
- gchar *path;
- GStatBuf s;
-
- path = folder_item_get_path(item);
- cm_return_val_if_fail(path != NULL, FALSE);
-
- if (g_stat(path, &s) < 0) {
- FILE_OP_ERROR(path, "stat");
- g_free(path);
+ char *path = folder_item_get_path(item);
+ if (path == NULL)
return FALSE;
+ struct stat sb;
+ if (stat(path, &sb) < 0) {
+ warn("stat %s", path);
+ free(path);
+ return FALSE;
}
+ free(path);
- if ((s.st_mtime > item->mtime) &&
- (s.st_mtime - 3600 != item->mtime)) {
- debug_print("MH scan required, folder updated: %s (%ld > %ld)\n",
- path,
- (long int) s.st_mtime,
- (long int) item->mtime);
- g_free(path);
+ if ((sb.st_mtime > item->mtime) && (sb.st_mtime - 3600 != item->mtime))
return TRUE;
- }
-
- debug_print("MH scan not required: %s (%ld <= %ld)\n",
- path,
- (long int) s.st_mtime,
- (long int) item->mtime);
- g_free(path);
return FALSE;
}
if (MSG_IS_MOVE(msginfo->flags)) {
msginfo->flags.tmp_flags &= ~MSG_MOVE_DONE;
- if (move_file(srcfile, destfile, TRUE) < 0) {
- FILE_OP_ERROR(srcfile, "move");
+ if (rename(srcfile, destfile) < 0) {
+ warn("rename %s to %s", srcfile, destfile);
if (copy_file(srcfile, destfile, TRUE) < 0) {
FILE_OP_ERROR(srcfile, "copy");
g_free(srcfile);
dest = mh_get_new_msg_filename(info->folder);
num = info->folder->last_num + 1;
- if (move_file(src, dest, FALSE) == 0) {
+ // only renumber the file if dest doesn't already exist.
+ // TODO(otl): why?
+ struct stat sb;
+ if (stat(dest, &sb) && errno == ENOENT) {
+ if (rename(src, dest) < 0) {
+ warn("rename %s to %s", src, dest);
+ free(src);
+ free(dest);
+ return FALSE;
+ }
msgcache_remove_msg(info->folder->cache, info->msgnum);
info->msgnum = num;
msgcache_add_msg(info->folder->cache, info);
}
}
- if (make_dir(fullpath) < 0) {
+ if (mkdir(fullpath, 0700) < 0) {
g_free(fullpath);
return NULL;
}
blob - f9651f836508fa3073f32715e70cbc9834c6322d
blob + e1fb7118c2123ab6826619556fe1498f061f9cef
--- src/msgcache.c
+++ src/msgcache.c
FILE_OP_ERROR(file, "g_fopen");
return NULL;
}
- if (change_file_mode_rw(fp, file) < 0)
- FILE_OP_ERROR(file, "chmod");
-
WRITE_CACHE_DATA_INT(version, fp);
if (w_err != 0) {
g_warning("failed to write int");
write_fps.tags_fp = NULL;
- if (write_fps.cache_fp || write_fps.mark_fp)
- debug_print("\tWriting message cache to %s and %s...\n", new_cache, new_mark);
-
- if (write_fps.cache_fp && change_file_mode_rw(write_fps.cache_fp, new_cache) < 0)
- FILE_OP_ERROR(new_cache, "chmod");
-
/* headers written, note file size */
if (write_fps.cache_fp)
write_fps.cache_size = ftell(write_fps.cache_fp);
} else {
/* switch files */
if (cache_file)
- move_file(new_cache, cache_file, TRUE);
+ rename(new_cache, cache_file);
if (mark_file)
- move_file(new_mark, mark_file, TRUE);
+ rename(new_mark, mark_file);
cache->last_access = time(NULL);
}
blob - 0a7786e1812fed0b88c24e683e9f81f5a97ba438
blob + 49c525e0ffdb988f1454ec17d1da9a39355fdf0e
--- src/pop.c
+++ src/pop.c
return -1;
}
- if (change_file_mode_rw(fp, file) < 0)
- FILE_OP_ERROR(file, "chmod");
-
if (prefix != NULL) {
if (fprintf(fp, "%s\n", prefix) < 0) {
FILE_OP_ERROR(file, "fprintf");
blob - b77bbd6d5366a3aa6554739e6b20f0265aba62e2
blob + f190952d31c3c6464ef074c5fedb031fadac7165
--- src/prefs_common.c
+++ src/prefs_common.c
goto out;
}
- if (change_file_mode_rw(fp, history) < 0) {
- FILE_OP_ERROR(history, "chmod");
- g_warning("can't change file mode: %s", history);
- }
-
for (cur = list; cur != NULL; cur = cur->next) {
TRY(fputs((gchar *)cur->data, fp) != EOF &&
fputc('\n', fp) != EOF);
blob - b1cd3fa46c62fee887fda391528e7e539f61d301
blob + 5b90ad6c2f30e636e5e30c6762ee157b7d56038c
--- src/procheader.c
+++ src/procheader.c
if (month_n >= 1 && month_n <= 12) {
strncpy2(month, monthstr+((month_n-1)*3), 4);
if (zonestr[0] == 'z' || zonestr[0] == 'Z') {
- strcat(zone, "+00:00");
+ strlcat(zone, "+00:00", sizeof(zone));
} else if (sscanf(zonestr, "%c%2d:%2d",
&offset_sign, &zone1, &zone2) == 3) {
- strcat(zone, zonestr);
+ strlcat(zone, zonestr, sizeof(zone));
}
return 0;
}
if (month_n >= 1 && month_n <= 12) {
strncpy2(month, monthstr+((month_n-1)*3), 4);
if (zonestr[0] == 'z' || zonestr[0] == 'Z') {
- strcat(zone, "+00:00");
+ strlcat(zone, "+00:00", sizeof(zone));
} else if (sscanf(zonestr, "%c%2d:%2d",
&offset_sign, &zone1, &zone2) == 3) {
- strcat(zone, zonestr);
+ strlcat(zone, zonestr, sizeof(zone));
}
return 0;
}
blob - 6694f52e5acbb40e8cb333f5eeaef4c33797c063
blob + 8c986a8c7b2bb9a500988114c2b73b0cddd7087f
--- src/procmime.c
+++ src/procmime.c
return -(saved_errno);
}
- if (change_file_mode_rw(outfp, outfile) < 0) {
- FILE_OP_ERROR(outfile, "chmod");
- g_warning("can't change file mode: %s", outfile);
- }
-
result = procmime_get_part_to_stream(outfp, mimeinfo);
if (fclose(outfp) == EOF) {