/* * gedit-vfs-save-utils.c * This file is part of gedit * * Copyright (C) 2005 - Paolo Borelli and Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ /* * Modified by the gedit Team, 2005. See the AUTHORS file for a * list of people on the gedit Team. * See the ChangeLog files for a list of changes. */ #include "gedit-vfs-save-utils.h" gboolean gedit_save_file (const gchar *uri, GeditGetDataCallback data_callback, gpointer callback_data, GError **error, const gchar *first_property_name, ...) { GnomeVFSURI *vfs_uri; GnomeVFSFileInfo *info = NULL; GnomeVFSResult vfs_res; gboolean new_file; g_return_val_if_fail ((uri != NULL) && (strlen (uri) > 0), FALSE); g_return_val_if_fail (data_callback != NULL, FALSE); if (strlen (uri) > GEDIT_MAX_PATH_LEN) { g_set_error (error, GEDIT_DOCUMENT_IO_ERROR, GNOME_VFS_ERROR_NAME_TOO_LONG, gnome_vfs_result_to_string (GNOME_VFS_ERROR_NAME_TOO_LONG)); return FALSE; } vfs_uri = gnome_vfs_uri_new (uri); if (vfs_uri == NULL) { g_set_error (error, GEDIT_DOCUMENT_IO_ERROR, GNOME_VFS_ERROR_INVALID_URI, gnome_vfs_result_to_string (GNOME_VFS_ERROR_INVALID_URI)); return FALSE; } // Set overwriting ??? Per ora no // Creazione buffer ??? Per ora no /* Get information about original file (if there is one) _following_ symlinks. */ info = gnome_vfs_file_info_new (); vfs_res = gnome_vfs_get_file_info_uri (vfs_uri, info, GNOME_VFS_FILE_INFO_DEFAULT | GNOME_VFS_FILE_INFO_FOLLOW_LINKS | GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS); new_file = FALSE; if (vfs_res == GNOME_VFS_ERROR_NOT_FOUND) { /* We are creating a new file */ new_file = TRUE; } // FINO QUI else if (vfs_res == GNOME_VFS_OK) /* If the file already exists */ { /* If the file already exists */ /* First of all check if the file is writable. * If access is not a valid info field (e.g. with ssh), assume * that it's writable and try to go on. */ if ((info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_ACCESS) && !(info->permissions & GNOME_VFS_PERM_ACCESS_WRITABLE)) { g_set_error (error, GEDIT_DOCUMENT_IO_ERROR, GNOME_VFS_ERROR_READ_ONLY, gnome_vfs_result_to_string (GNOME_VFS_ERROR_READ_ONLY)); goto out; } /* check if is regular file */ if ((info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) && !(info->type == GNOME_VFS_FILE_TYPE_REGULAR)) { g_set_error (error, GEDIT_DOCUMENT_IO_ERROR, GNOME_VFS_ERROR_GENERIC, gnome_vfs_result_to_string (GNOME_VFS_ERROR_GENERIC)); goto out; } /* check if it's a hard link */ if ((info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_LINK_COUNT) && (info->link_count > 1)) { is_link = TRUE; } /* if not a hard link, check if is a symlink */ if (!is_link) is_link = uri_is_symlink (vfs_uri); } else /* there were other errors getting info of old file: error out */ { g_set_error (error, GEDIT_DOCUMENT_IO_ERROR, vfs_res, gnome_vfs_result_to_string (vfs_res)); goto out; } return TRUE; }