49 | 49 |
#include "gedit-marshal.h"
|
50 | 50 |
#include "gedit-utils.h"
|
51 | 51 |
|
|
52 |
#ifdef HAVE_LIBATTR
|
|
53 |
#include <attr/libattr.h>
|
|
54 |
#else
|
|
55 |
#define attr_copy_fd(x1, x2, x3, x4, x5, x6) (errno = ENOSYS, -1)
|
|
56 |
#endif
|
|
57 |
|
52 | 58 |
#define GEDIT_DOCUMENT_SAVER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \
|
53 | 59 |
GEDIT_TYPE_DOCUMENT_SAVER, \
|
54 | 60 |
GeditDocumentSaverPrivate))
|
|
456 | 462 |
|
457 | 463 |
/* ----------- local files ----------- */
|
458 | 464 |
|
|
465 |
#ifdef HAVE_LIBATTR
|
|
466 |
/* Save everything: user/root xattrs, SELinux, ACLs. */
|
|
467 |
static int
|
|
468 |
all_xattrs (const char *xattr G_GNUC_UNUSED,
|
|
469 |
struct error_context *err G_GNUC_UNUSED)
|
|
470 |
{
|
|
471 |
return 1;
|
|
472 |
}
|
|
473 |
#endif
|
|
474 |
|
459 | 475 |
static gboolean
|
460 | 476 |
save_existing_local_file (GeditDocumentSaver *saver)
|
461 | 477 |
{
|
|
596 | 612 |
goto fallback_strategy;
|
597 | 613 |
}
|
598 | 614 |
|
|
615 |
/* copy the xattrs, like user.mime_type, over. Also ACLs and
|
|
616 |
* SELinux context. */
|
|
617 |
if ((attr_copy_fd (saver->priv->local_path,
|
|
618 |
saver->priv->fd,
|
|
619 |
tmp_filename,
|
|
620 |
tmpfd,
|
|
621 |
all_xattrs,
|
|
622 |
NULL) == -1) &&
|
|
623 |
(errno != EOPNOTSUPP) && (errno != ENOSYS))
|
|
624 |
{
|
|
625 |
gedit_debug_message (DEBUG_SAVER, "could not set xattrs");
|
|
626 |
|
|
627 |
close (tmpfd);
|
|
628 |
unlink (tmp_filename);
|
|
629 |
g_free (tmp_filename);
|
|
630 |
|
|
631 |
goto fallback_strategy;
|
|
632 |
}
|
|
633 |
|
599 | 634 |
if (!write_document_contents (tmpfd,
|
600 | 635 |
GTK_TEXT_BUFFER (saver->priv->document),
|
601 | 636 |
saver->priv->encoding,
|
|
748 | 783 |
|
749 | 784 |
goto out;
|
750 | 785 |
}
|
|
786 |
}
|
|
787 |
|
|
788 |
/* copy the xattrs, like user.mime_type, over. Also ACLs and
|
|
789 |
* SELinux context. */
|
|
790 |
if ((attr_copy_fd (saver->priv->local_path,
|
|
791 |
saver->priv->fd,
|
|
792 |
backup_filename,
|
|
793 |
bfd,
|
|
794 |
all_xattrs,
|
|
795 |
NULL) == -1) &&
|
|
796 |
(errno != EOPNOTSUPP) && (errno != ENOSYS))
|
|
797 |
{
|
|
798 |
gedit_debug_message (DEBUG_SAVER, "could not set xattrs");
|
|
799 |
|
|
800 |
g_set_error (&saver->priv->error,
|
|
801 |
GEDIT_DOCUMENT_ERROR,
|
|
802 |
GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
|
|
803 |
"No backup created");
|
|
804 |
|
|
805 |
unlink (backup_filename);
|
|
806 |
close (bfd);
|
|
807 |
|
|
808 |
goto out;
|
751 | 809 |
}
|
752 | 810 |
|
753 | 811 |
if (!copy_file_data (saver->priv->fd, bfd, NULL))
|