lib/mu-msg-file: Use canonical path instead of real path
For the new symlink-support, it's better to use the *canonical* path than the *realpath(3)* for files, so removing a symlinked maildir will work as expected.
This commit is contained in:
@ -70,6 +70,9 @@ mu_msg_file_destroy (MuMsgFile *self)
|
|||||||
if (self->_mime_msg)
|
if (self->_mime_msg)
|
||||||
g_object_unref (self->_mime_msg);
|
g_object_unref (self->_mime_msg);
|
||||||
|
|
||||||
|
g_free(self->_path);
|
||||||
|
g_free(self->_maildir);
|
||||||
|
|
||||||
g_slice_free (MuMsgFile, self);
|
g_slice_free (MuMsgFile, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +82,12 @@ init_file_metadata (MuMsgFile *self, const char* path, const gchar* mdir,
|
|||||||
{
|
{
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
|
||||||
|
if (!g_path_is_absolute (path)) {
|
||||||
|
mu_util_g_set_error (err, MU_ERROR_FILE,
|
||||||
|
"path '%s' is not absolute", path);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (access (path, R_OK) != 0) {
|
if (access (path, R_OK) != 0) {
|
||||||
mu_util_g_set_error (err, MU_ERROR_FILE,
|
mu_util_g_set_error (err, MU_ERROR_FILE,
|
||||||
"cannot read file %s: %s",
|
"cannot read file %s: %s",
|
||||||
@ -101,16 +110,9 @@ init_file_metadata (MuMsgFile *self, const char* path, const gchar* mdir,
|
|||||||
|
|
||||||
self->_timestamp = statbuf.st_mtime;
|
self->_timestamp = statbuf.st_mtime;
|
||||||
self->_size = (size_t)statbuf.st_size;
|
self->_size = (size_t)statbuf.st_size;
|
||||||
|
self->_path = g_canonicalize_filename(path, NULL);
|
||||||
|
self->_maildir = g_strdup(mdir ? mdir : "");
|
||||||
|
|
||||||
/* remove double slashes, relative paths etc. from path & mdir */
|
|
||||||
if (!realpath (path, self->_path)) {
|
|
||||||
mu_util_g_set_error (err, MU_ERROR_FILE,
|
|
||||||
"could not get realpath for %s: %s",
|
|
||||||
path, strerror(errno));
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
strncpy (self->_maildir, mdir ? mdir : "", PATH_MAX);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -40,8 +40,8 @@ struct _MuMsgFile {
|
|||||||
GMimeMessage *_mime_msg;
|
GMimeMessage *_mime_msg;
|
||||||
time_t _timestamp;
|
time_t _timestamp;
|
||||||
size_t _size;
|
size_t _size;
|
||||||
char _path [PATH_MAX + 1];
|
char *_path;
|
||||||
char _maildir [PATH_MAX + 1];
|
char *_maildir;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user