+2002-08-08
+
+ * src/utils.[ch]: get_tmp_file(): new. Returns the directory for
+ temporary files in ~/.sylpheed/.
+ * src/main.c: create temporary directory in ~/.sylpheed/.
+ * src/compose.c
+ src/inc.c: create temporary files in ~/.sylpheed/, and modified
+ the file name.
+ compose_exec_ext_editor(): fixed a bug that failed to create the
+ temporary file if g_get_tmp_dir() returned directory other than
+ '/tmp'.
+
+2002-08-08
+
+ * src/utils.c: copy_file(): check if dest_bak != NULL when unlinking.
+
+2002-08-08
+
+ * src/utils.[ch]: canonicalize_file_replace(): fixed a bug that fails
+ to replace the file when the given file and temporary file are not
+ on the same filesystem.
+ copy_file(): added a flag whether to keep backup.
+ move_file(): added a flag whether to overwrite the destination file.
+
2002-08-07
* src/socket.[ch]: fixed the linking failure when IPv6 is enabled.
+2002-08-08 [paul] 0.8.1claws36
+
+ * sync with 0.8.1cvs19
+ see ChangeLog 2002-08-08
+
2002-08-07 [christoph] 0.8.1claws35
* src/utils.c
+2002-08-08
+
+ * src/utils.[ch]: get_tmp_file(): ¿·µ¬¡£ ~/.sylpheed/ Ãæ¤Î¥Æ¥ó¥Ý¥é¥ê
+ ¥Õ¥¡¥¤¥ëÍѤΥǥ£¥ì¥¯¥È¥ê¤òÊÖ¤¹¡£
+ * src/main.c: ~/.sylpheed/ Ãæ¤Ë¥Æ¥ó¥Ý¥é¥ê¥Ç¥£¥ì¥¯¥È¥ê¤òºîÀ®¡£
+ * src/compose.c
+ src/inc.c: ~/.sylpheed/ Ãæ¤Ë¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë¤òºî¤ë¤è¤¦¤Ë¤·¡¢
+ ¥Õ¥¡¥¤¥ë̾¤ò½¤Àµ¡£
+ compose_exec_ext_editor(): g_get_tmp_dir() ¤¬ '/tmp' °Ê³°¤òÊÖ¤·¤¿
+ ¤È¤¤Ë¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë¤ÎºîÀ®¤Ë¼ºÇÔ¤¹¤ë¥Ð¥°¤ò½¤Àµ¡£
+
+2002-08-08
+
+ * src/utils.c: copy_file(): unlink ¤¹¤ë¤È¤¤Ë dest_bak != NULL ¤«
+ ¤É¤¦¤«¤ò¥Á¥§¥Ã¥¯¡£
+
+2002-08-08
+
+ * src/utils.[ch]: canonicalize_file_replace(): Í¿¤¨¤é¤ì¤¿¥Õ¥¡¥¤¥ë¤È
+ °ì»þ¥Õ¥¡¥¤¥ë¤¬Æ±¤¸¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¾å¤Ë¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¥Õ¥¡¥¤¥ë¤Î
+ ÃÖ¤´¹¤¨¤Ë¼ºÇÔ¤¹¤ë¥Ð¥°¤ò½¤Àµ¡£
+ copy_file(): ¥Ð¥Ã¥¯¥¢¥Ã¥×¤òÊÝ»ý¤¹¤ë¤«¤É¤¦¤«¤Î¥Õ¥é¥°¤òÄɲá£
+ move_file(): °ÜÆ°Àè¥Õ¥¡¥¤¥ë¤ò¾å½ñ¤¤¹¤ë¤«¤É¤¦¤«¤Î¥Õ¥é¥°¤òÄɲá£
+
2002-08-07
* src/socket.[ch]: IPv6 ¤¬Í¸ú¤Ê¾ì¹ç¤Ë¥ê¥ó¥¯¤Ë¼ºÇÔ¤¹¤ë¤Î¤ò½¤Àµ¡£
MICRO_VERSION=1
INTERFACE_AGE=0
BINARY_AGE=0
-EXTRA_VERSION=claws35
+EXTRA_VERSION=claws36
VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
dnl set $target
static void compose_exec_ext_editor(Compose *compose)
{
- gchar tmp[64];
+ gchar *tmp;
pid_t pid;
gint pipe_fds[2];
- g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
- g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
+ tmp = g_strdup_printf("%s%ctmpmsg.%08x", get_tmp_dir(),
+ G_DIR_SEPARATOR, (gint)compose);
if (pipe(pipe_fds) < 0) {
perror("pipe");
+ g_free(tmp);
return;
}
if ((pid = fork()) < 0) {
perror("fork");
+ g_free(tmp);
return;
}
close(pipe_fds[1]);
_exit(0);
}
+
+ g_free(tmp);
}
static gint compose_exec_ext_editor_real(const gchar *file)
lock = TRUE;
- tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
+ tmp = g_strdup_printf("%s%cdraft.%08x", get_tmp_dir(),
G_DIR_SEPARATOR, (gint)compose);
if (compose_write_to_file(compose, tmp, TRUE) < 0) {
#define RENDERER_RC "rendererrc"
#define COMMAND_HISTORY "command_history"
#define TEMPLATE_DIR "templates"
+#define TMP_DIR "tmp"
#define NEWSGROUP_LIST ".newsgroup_list"
#define ADDRESS_BOOK "addressbook.xml"
#define MANUAL_HTML_INDEX "sylpheed.html"
if ((lockfd = lock_mbox(mbox, LOCK_FLOCK)) < 0)
return -1;
- g_snprintf(tmp_mbox, sizeof(tmp_mbox), "%s%ctmpmbox%d",
- get_rc_dir(), G_DIR_SEPARATOR, (gint)mbox);
+ g_snprintf(tmp_mbox, sizeof(tmp_mbox), "%s%ctmpmbox.%08x",
+ get_tmp_dir(), G_DIR_SEPARATOR, (gint)mbox);
if (copy_mbox(mbox, tmp_mbox) < 0) {
unlock_mbox(mbox, lockfd, LOCK_FLOCK);
MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir());
MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir());
MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
+ MAKE_DIR_IF_NOT_EXIST(get_tmp_dir());
MAKE_DIR_IF_NOT_EXIST(RC_DIR G_DIR_SEPARATOR_S "uidl");
if (is_file_exist(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log")) {
gint copy_mbox(const gchar *src, const gchar *dest)
{
- return copy_file(src, dest);
+ return copy_file(src, dest, TRUE);
}
void empty_mbox(const gchar *mbox)
g_return_val_if_fail(destfile != NULL, -1);
if (link(file, destfile) < 0) {
- if (copy_file(file, destfile) < 0) {
+ if (copy_file(file, destfile, TRUE) < 0) {
g_warning(_("can't copy message %s to %s\n"),
file, destfile);
g_free(destfile);
srcfile = procmsg_get_message_file(msginfo);
- if (move_file(srcfile, destfile) < 0) {
+ if (move_file(srcfile, destfile, FALSE) < 0) {
g_free(srcfile);
g_free(destfile);
return -1;
destfile = mh_get_new_msg_filename(dest);
if(!destfile) return -1;
- if (move_file(srcfile, destfile) < 0) {
+ if (move_file(srcfile, destfile, FALSE) < 0) {
g_free(srcfile);
g_free(destfile);
break;
g_free(srcfile);
return -1;
}
-
- if (copy_file(srcfile, destfile) < 0) {
+
+ if (copy_file(srcfile, destfile, TRUE) < 0) {
FILE_OP_ERROR(srcfile, "copy");
g_free(srcfile);
g_free(destfile);
if (!destfile) break;
srcfile = procmsg_get_message_file(msginfo);
- if (copy_file(srcfile, destfile) < 0) {
+ if (copy_file(srcfile, destfile, TRUE) < 0) {
FILE_OP_ERROR(srcfile, "copy");
g_free(srcfile);
g_free(destfile);
}
src = procmsg_get_message_file(msginfo);
- if (copy_file(src, dest) < 0) {
+ if (copy_file(src, dest, TRUE) < 0) {
alertpanel_error(_("Can't save the file `%s'."),
g_basename(dest));
}
return header_dir;
}
+gchar *get_tmp_dir(void)
+{
+ static gchar *tmp_dir = NULL;
+
+ if (!tmp_dir)
+ tmp_dir = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+ TMP_DIR, NULL);
+
+ return tmp_dir;
+}
+
gchar *get_tmp_file(void)
{
static gchar *tmp_file = NULL;
if (!tmp_file)
- tmp_file = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+ tmp_file = g_strconcat(get_tmp_dir(), G_DIR_SEPARATOR_S,
"tmpfile", NULL);
return tmp_file;
}
#endif
-gint copy_file(const gchar *src, const gchar *dest)
+gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup)
{
FILE *src_fp, *dest_fp;
gint n_read;
return -1;
}
+ if (keep_backup == FALSE && dest_bak)
+ unlink(dest_bak);
+
g_free(dest_bak);
return 0;
}
-gint move_file(const gchar *src, const gchar *dest)
+gint move_file(const gchar *src, const gchar *dest, gboolean overwrite)
{
- if (is_file_exist(dest)) {
+ if (overwrite == FALSE && is_file_exist(dest)) {
g_warning(_("move_file(): file %s already exists."), dest);
return -1;
}
return -1;
}
- if (copy_file(src, dest) < 0) return -1;
+ if (copy_file(src, dest, FALSE) < 0) return -1;
unlink(src);
/* convert line endings into CRLF. If the last line doesn't end with
* linebreak, add it.
*/
-gint canonicalize_file(FILE *src_fp, FILE *dest_fp)
+gint canonicalize_file(const gchar *src, const gchar *dest)
{
+ FILE *src_fp, *dest_fp;
gchar buf[BUFFSIZE];
gint len;
gboolean err = FALSE;
gboolean last_linebreak = FALSE;
- rewind(src_fp);
- rewind(dest_fp);
+ if ((src_fp = fopen(src, "rb")) == NULL) {
+ FILE_OP_ERROR(src, "fopen");
+ return -1;
+ }
+
+ if ((dest_fp = fopen(dest, "wb")) == NULL) {
+ FILE_OP_ERROR(dest, "fopen");
+ fclose(src_fp);
+ return -1;
+ }
+
+ if (change_file_mode_rw(dest_fp, dest) < 0) {
+ FILE_OP_ERROR(dest, "chmod");
+ g_warning("can't change file mode\n");
+ }
+
while (fgets(buf, sizeof(buf), src_fp) != NULL) {
gint r = 0;
}
if (r == EOF) {
- g_warning("writing to destination file failed.\n");
-
+ g_warning("writing to %s failed.\n", dest);
+ fclose(dest_fp);
+ fclose(src_fp);
+ unlink(dest);
return -1;
}
}
err = TRUE;
}
+ if (ferror(src_fp)) {
+ FILE_OP_ERROR(src, "fread");
+ err = TRUE;
+ }
+ fclose(src_fp);
+ if (fclose(dest_fp) == EOF) {
+ FILE_OP_ERROR(dest, "fclose");
+ err = TRUE;
+ }
+
if (err) {
+ unlink(dest);
return -1;
}
gint canonicalize_file_replace(const gchar *file)
{
- gchar *tmp_file, *dirname;
- FILE *src, *dest;
+ gchar *tmp_file;
- src = fopen(file, "r");
+ tmp_file = get_tmp_file();
- dirname = g_dirname(file);
- dest = get_tmpfile_in_dir(dirname, &tmp_file);
- g_free(dirname);
-
- debug_print("Writing canonicalized file to %s\n", tmp_file);
-
- if (canonicalize_file(src, dest) < 0) {
- fclose(dest);
- fclose(src);
-
- g_free(tmp_file);
+ if (canonicalize_file(file, tmp_file) < 0)
return -1;
- }
- fclose(dest);
- fclose(src);
- unlink(file);
- if (rename(tmp_file, file) < 0) {
+ if (move_file(tmp_file, file, TRUE) < 0) {
FILE_OP_ERROR(file, "rename");
unlink(tmp_file);
-
- g_free(tmp_file);
return -1;
}
- g_free(tmp_file);
return 0;
}
gint fd;
FILE *fp;
- tmpdir = g_get_tmp_dir();
+ tmpdir = get_tmp_dir();
tmplen = strlen(tmpdir);
progname = g_get_prgname();
proglen = strlen(progname);
gchar *get_mime_tmp_dir (void);
gchar *get_template_dir (void);
gchar *get_header_cache_dir (void);
+gchar *get_tmp_dir (void);
gchar *get_tmp_file (void);
gchar *get_domain_name (void);
guint hours);
gint remove_dir_recursive (const gchar *dir);
gint copy_file (const gchar *src,
- const gchar *dest);
+ const gchar *dest,
+ gboolean keep_backup);
gint move_file (const gchar *src,
+ const gchar *dest,
+ gboolean overwrite);
+gint canonicalize_file (const gchar *src,
const gchar *dest);
gint canonicalize_file_replace (const gchar *file);
gint change_file_mode_rw (FILE *fp,
const gchar *file);
FILE *my_tmpfile (void);
FILE *str_open_as_stream (const gchar *str);
-FILE *get_tmpfile_in_dir (const gchar *dir,
- gchar **filename);
/* process execution */
gint execute_async (gchar *const argv[]);