static void saved_query_info_cb (GFile *location, GAsyncResult *result, GeditDocument *doc) { GFileInfo *info; const gchar *content_type = NULL; GError *error = NULL; info = g_file_query_info_finish (location, result, &error); if (error != NULL) { g_warning ("Document saving: query info error: %s", error->message); g_error_free (error); error = NULL; } doc->priv->mtime_set = FALSE; if (info != NULL) { if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) { content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); } if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) { g_file_info_get_modification_time (info, &doc->priv->mtime); doc->priv->mtime_set = TRUE; } } gedit_document_set_content_type (doc, content_type); if (info != NULL) { /* content_type (owned by info) is no longer needed. */ g_object_unref (info); } g_get_current_time (&doc->priv->time_of_last_save_or_load); doc->priv->externally_modified = FALSE; doc->priv->deleted = FALSE; doc->priv->create = FALSE; set_readonly (doc, FALSE); gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), FALSE); save_encoding_metadata (doc); /* Async operation finished. */ g_object_unref (doc); }
static void loaded_query_info_cb (GFile *location, GAsyncResult *result, GeditDocument *doc) { GFileInfo *info; GError *error = NULL; info = g_file_query_info_finish (location, result, &error); if (error != NULL) { /* Ignore not found error as it can happen when opening a * non-existent file from the command line. */ if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_NOT_FOUND) { g_warning ("Document loading: query info error: %s", error->message); } g_error_free (error); error = NULL; } if (info != NULL) { if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) { const gchar *content_type; content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); gedit_document_set_content_type (doc, content_type); } if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { gboolean read_only; read_only = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); set_readonly (doc, read_only); } if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) { g_file_info_get_modification_time (info, &doc->priv->mtime); doc->priv->mtime_set = TRUE; } g_object_unref (info); } /* Async operation finished. */ g_object_unref (doc); }
static void check_file_on_disk (GeditDocument *doc) { GFile *location; GFileInfo *info; location = gtk_source_file_get_location (doc->priv->file); if (location == NULL) { return; } info = g_file_query_info (location, G_FILE_ATTRIBUTE_TIME_MODIFIED "," \ G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info != NULL) { /* While at it also check if permissions changed */ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { gboolean read_only; read_only = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); set_readonly (doc, read_only); } if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED) && doc->priv->mtime_set) { GTimeVal timeval; g_file_info_get_modification_time (info, &timeval); /* Note that mtime can even go backwards if the * user is copying over a file with an old mtime */ if (timeval.tv_sec != doc->priv->mtime.tv_sec || timeval.tv_usec != doc->priv->mtime.tv_usec) { doc->priv->externally_modified = TRUE; } } g_object_unref (info); } else { doc->priv->deleted = TRUE; } }
/** * gtk_source_file_check_file_on_disk: * @file: a #GtkSourceFile. * * Checks synchronously the file on disk, to know whether the file is externally * modified, or has been deleted, and whether the file is read-only. * * #GtkSourceFile doesn't create a #GFileMonitor to track those properties, so * this function needs to be called instead. Creating lots of #GFileMonitor's * would take lots of resources. * * Since this function is synchronous, it is advised to call it only on local * files. See gtk_source_file_is_local(). * * Since: 3.18 */ void gtk_source_file_check_file_on_disk (GtkSourceFile *file) { GFileInfo *info; if (file->priv->location == NULL) { return; } info = g_file_query_info (file->priv->location, G_FILE_ATTRIBUTE_TIME_MODIFIED "," G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info == NULL) { file->priv->deleted = TRUE; return; } if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED) && file->priv->modification_time_set) { GTimeVal timeval; g_file_info_get_modification_time (info, &timeval); /* Note that the modification time can even go backwards if the * user is copying over an old file. */ if (timeval.tv_sec != file->priv->modification_time.tv_sec || timeval.tv_usec != file->priv->modification_time.tv_usec) { file->priv->externally_modified = TRUE; } } if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { gboolean readonly; readonly = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); _gtk_source_file_set_readonly (file, readonly); } g_object_unref (info); }
static gboolean is_read_only (GFile *location) { gboolean ret = TRUE; /* default to read only */ GFileInfo *info; cedit_debug (DEBUG_COMMANDS); info = g_file_query_info (location, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info != NULL) { if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { ret = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); } g_object_unref (info); } return ret; }
static gboolean _should_process (GFileInfo *info) { /* check that the file is non-hidden and readable */ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ)) { if (g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ) == FALSE) { return FALSE; } } if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN)) { if (g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN)) { return FALSE; } } return TRUE; }
static gboolean get_file_mtime (const char *file_uri, time_t* mtime) { GFile *file; GFileInfo *info; gboolean ret; ret = FALSE; *mtime = INVALID_MTIME; file = g_file_new_for_uri (file_uri); info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, 0, NULL, NULL); if (info) { if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) { *mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED); ret = TRUE; } g_object_unref (info); } g_object_unref (file); return ret; }
static toff_t get_file_size(thandle_t handle) { Priv *p = (Priv*) handle; GError *error = NULL; GFileInfo *info; goffset size; g_assert(p->stream); size = p->allocated; if (p->file != NULL) { info = g_file_query_info(p->file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &error); if (info == NULL) { g_warning("%s", error->message); g_error_free(error); } else { if (g_file_info_has_attribute(info, G_FILE_ATTRIBUTE_STANDARD_SIZE)) size = g_file_info_get_size(info); g_object_unref(info); } } return (toff_t) size; }
/** * is_read_only: * @location: a GFile Object that represents the file to check * * This method is copied from gedit, file gedit-commands-file.c * * Returns: False if file is writeable. True if file doesn't exists, is read-only or read-only attribute can't be check */ static gboolean is_read_only (const gchar * filename) { gboolean ret = TRUE; /* default to read only */ GFileInfo *info; GFile *location; location = g_file_new_for_path (filename); if (!g_file_query_exists (location, NULL)) return FALSE; info = g_file_query_info (location, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (location); if (info != NULL) { if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { ret = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); } g_object_unref (info); } return ret; }
static EogThumbData* eog_thumb_data_new (GFile *file, GError **error) { EogThumbData *data; GFileInfo *file_info; GError *ioerror = NULL; g_return_val_if_fail (file != NULL, NULL); g_return_val_if_fail (error != NULL && *error == NULL, NULL); data = g_slice_new0 (EogThumbData); data->uri_str = g_file_get_uri (file); data->thumb_path = gnome_desktop_thumbnail_path_for_uri (data->uri_str, GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL); file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_TIME_MODIFIED "," G_FILE_ATTRIBUTE_THUMBNAIL_PATH "," G_FILE_ATTRIBUTE_THUMBNAILING_FAILED "," G_FILE_ATTRIBUTE_ACCESS_CAN_READ, 0, NULL, &ioerror); if (file_info == NULL) { set_vfs_error (error, ioerror); g_clear_error (&ioerror); } if (*error == NULL) { /* if available, copy data */ data->mtime = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED); data->mime_type = g_strdup (g_file_info_get_content_type (file_info)); data->thumb_exists = (g_file_info_get_attribute_byte_string (file_info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH) != NULL); data->failed_thumb_exists = g_file_info_get_attribute_boolean (file_info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED); data->can_read = TRUE; if (g_file_info_has_attribute (file_info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ)) { data->can_read = g_file_info_get_attribute_boolean (file_info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ); } } else { eog_thumb_data_free (data); data = NULL; g_clear_error (&ioerror); } g_object_unref (file_info); return data; }
static gint mode_from_flags_or_info (GFileCreateFlags flags, GFileInfo *reference_info) { if (flags & G_FILE_CREATE_PRIVATE) return 0600; else if (reference_info && g_file_info_has_attribute (reference_info, "unix::mode")) return g_file_info_get_attribute_uint32 (reference_info, "unix::mode") & (~S_IFMT); else return 0666; }
gchar * gitg_utils_get_content_type(GFile *file) { GFileInfo *info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (!info || !g_file_info_has_attribute(info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) return NULL; gchar *content_type = g_strdup(g_file_info_get_content_type(info)); g_object_unref(info); return content_type; }
/** * gedit_document_get_metadata: * @doc: a #GeditDocument * @key: name of the key * * Gets the metadata assigned to @key. * * Returns: the value assigned to @key. Free with g_free(). */ gchar * gedit_document_get_metadata (GeditDocument *doc, const gchar *key) { g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL); g_return_val_if_fail (key != NULL, NULL); if (doc->priv->metadata_info != NULL && g_file_info_has_attribute (doc->priv->metadata_info, key)) { return g_strdup (g_file_info_get_attribute_string (doc->priv->metadata_info, key)); } return NULL; }
static gchar * get_metadata_from_gvfs (GeditDocument *doc, const gchar *key) { GeditDocumentPrivate *priv; priv = gedit_document_get_instance_private (doc); if (priv->metadata_info != NULL && g_file_info_has_attribute (priv->metadata_info, key)) { return g_strdup (g_file_info_get_attribute_string (priv->metadata_info, key)); } return NULL; }
/** * as_utils_is_writable: * @path: the path to check. * * Checks if a path is writable. */ gboolean as_utils_is_writable (const gchar *path) { g_autoptr(GFile) file = NULL; g_autoptr(GFileInfo) file_info = NULL; file = g_file_new_for_path (path); file_info = g_file_query_info ( file, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (file_info && g_file_info_has_attribute (file_info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) return g_file_info_get_attribute_boolean (file_info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); return FALSE; }
guint64 get_fs_property (const char *mountpoint, const char *attr) { GFile *root; GFileInfo *info; guint64 value; root = g_file_new_for_path (mountpoint); info = g_file_query_filesystem_info (root, attr, NULL, NULL); g_object_unref (G_OBJECT (root)); if (info == NULL) { return 0; } if (!g_file_info_has_attribute (info, attr)) { g_object_unref (G_OBJECT (info)); return 0; } value = g_file_info_get_attribute_uint64 (info, attr); g_object_unref (G_OBJECT (info)); return value; }
static void loaded_query_info_cb (GFile *location, GAsyncResult *result, GeditDocument *doc) { GFileInfo *info; GError *error = NULL; info = g_file_query_info_finish (location, result, &error); if (error != NULL) { /* Ignore not found error as it can happen when opening a * non-existent file from the command line. */ if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_NOT_FOUND) { g_warning ("Document loading: query info error: %s", error->message); } g_error_free (error); error = NULL; } if (info != NULL && g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) { const gchar *content_type; content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); set_content_type (doc, content_type); } g_clear_object (&info); /* Async operation finished. */ g_object_unref (doc); }
static void _panel_key_file_make_executable (const gchar *path) { GFile *file; GFileInfo *info; guint32 current_perms; guint32 new_perms; file = g_file_new_for_path (path); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE"," G_FILE_ATTRIBUTE_UNIX_MODE, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); if (info == NULL) { g_warning ("Cannot mark %s executable", path); g_object_unref (file); return; } if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE)) { current_perms = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE); new_perms = current_perms | S_IXGRP | S_IXUSR | S_IXOTH; if ((current_perms != new_perms) && !g_file_set_attribute_uint32 (file, G_FILE_ATTRIBUTE_UNIX_MODE, new_perms, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL)) g_warning ("Cannot mark %s executable", path); } g_object_unref (info); g_object_unref (file); }
/* FIXME: This should probably be an inline */ static gboolean file_info_is_image (GFileInfo *info) { gboolean is_image; const char *content_type; g_return_val_if_fail (info != NULL, FALSE); if (! g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) { return FALSE; } content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); if (content_type == NULL) { return FALSE; } is_image = (strcmp (content_type, "application/x-cd-image") == 0); return is_image; }
static guint64 get_fs_property (RBGenericPlayerSource *source, const char *attr) { char *mountpoint; GFile *root; GFileInfo *info; guint64 value = 0; mountpoint = rb_generic_player_source_get_mount_path (source); root = g_file_new_for_uri (mountpoint); g_free (mountpoint); info = g_file_query_filesystem_info (root, attr, NULL, NULL); g_object_unref (root); if (info != NULL) { if (g_file_info_has_attribute (info, attr)) { value = g_file_info_get_attribute_uint64 (info, attr); } g_object_unref (info); } return value; }
gboolean can_trash_file (GFile *file) { GFileInfo *info; gboolean can_trash = FALSE; info = g_file_query_info (file, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info) { if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH)) { can_trash = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH); } g_object_unref (info); } return can_trash; }
static gboolean xmms_gvfs_init (xmms_xform_t *xform) { xmms_gvfs_data_t *data; GFile *file; GFileInfo *info; GFileInputStream *handle; GError *error = NULL; const gchar *url; url = xmms_xform_indata_get_str (xform, XMMS_STREAM_TYPE_URL); g_return_val_if_fail (url, FALSE); /* This is an ugly hack to handle files with chars needing url encoding */ if (!g_ascii_strncasecmp (url, "file://", 7)) { file = g_file_new_for_path (url+7); } else { file = g_file_new_for_uri (url); } handle = g_file_read (file, NULL, &error); g_object_unref (file); if (!handle) { xmms_log_error ("Failed to upen url %s for reading: %s", url, error->message); return FALSE; } data = g_new (xmms_gvfs_data_t, 1); data->handle = G_INPUT_STREAM (handle); xmms_xform_private_data_set (xform, data); info = g_file_input_stream_query_info (handle, (char *)query_attributes, NULL, &error); if (!info) { xmms_log_info ("failed to query information for %s", url); } else { int i; for (i = 0; i < G_N_ELEMENTS (attr_map); i++) { if (!g_file_info_has_attribute (info, attr_map[i].gvfs)) { continue; } switch (attr_map[i].type) { case XMMSV_TYPE_STRING: { gchar *attr = g_file_info_get_attribute_as_string (info, attr_map[i].gvfs); xmms_xform_metadata_set_str (xform, attr_map[i].mlib, attr); g_free (attr); break; } case XMMSV_TYPE_INT32: { /* right now the xform metadata api only handles strings * and 32 bit ints. however the gvfs api returns uint64 for * the numeric attributes we're interested in and we just * pass that to the xform and pray that it doesn't overflow * as we know it's unsafe. */ gint64 attr = g_file_info_get_attribute_uint64 (info, attr_map[i].gvfs); xmms_xform_metadata_set_int (xform, attr_map[i].mlib, attr); break; } default: g_assert_not_reached (); } } g_object_unref (info); } xmms_xform_outdata_type_add (xform, XMMS_STREAM_TYPE_MIMETYPE, "application/octet-stream", XMMS_STREAM_TYPE_END); return TRUE; }
gboolean thunar_dialogs_show_insecure_program (gpointer parent, const gchar *primary, ThunarFile *file, const gchar *command) { GdkScreen *screen; GtkWindow *window; gint response; GtkWidget *dialog; GString *secondary; ThunarFileMode old_mode; ThunarFileMode new_mode; GFileInfo *info; GError *err = NULL; _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE); _thunar_return_val_if_fail (g_utf8_validate (command, -1, NULL), FALSE); /* parse the parent window and screen */ screen = thunar_util_parse_parent (parent, &window); /* secondary text */ secondary = g_string_new (NULL); g_string_append_printf (secondary, _("The desktop file \"%s\" is in an insecure location " "and not marked as executable. If you do not trust " "this program, click Cancel."), thunar_file_get_display_name (file)); g_string_append (secondary, "\n\n"); if (exo_str_looks_like_an_uri (command)) g_string_append_printf (secondary, G_KEY_FILE_DESKTOP_KEY_URL"=%s", command); else g_string_append_printf (secondary, G_KEY_FILE_DESKTOP_KEY_EXEC"=%s", command); /* allocate and display the error message dialog */ dialog = gtk_message_dialog_new (window, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, "%s", primary); gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Launch Anyway"), GTK_RESPONSE_OK); if (thunar_file_is_chmodable (file)) gtk_dialog_add_button (GTK_DIALOG (dialog), _("Mark _Executable"), GTK_RESPONSE_APPLY); gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL); if (screen != NULL && window == NULL) gtk_window_set_screen (GTK_WINDOW (dialog), screen); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", secondary->str); g_string_free (secondary, TRUE); response = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); /* check if we should make the file executable */ if (response == GTK_RESPONSE_APPLY) { /* try to query information about the file */ info = g_file_query_info (thunar_file_get_file (file), G_FILE_ATTRIBUTE_UNIX_MODE, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &err); if (G_LIKELY (info != NULL)) { if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE)) { /* determine the current mode */ old_mode = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE); /* generate the new mode */ new_mode = old_mode | THUNAR_FILE_MODE_USR_EXEC | THUNAR_FILE_MODE_GRP_EXEC | THUNAR_FILE_MODE_OTH_EXEC; if (old_mode != new_mode) { g_file_set_attribute_uint32 (thunar_file_get_file (file), G_FILE_ATTRIBUTE_UNIX_MODE, new_mode, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &err); } } else { g_warning ("No %s attribute found", G_FILE_ATTRIBUTE_UNIX_MODE); } g_object_unref (info); } if (err != NULL) { thunar_dialogs_show_error (parent, err, ("Unable to mark launcher executable")); g_error_free (err); } /* just launch */ response = GTK_RESPONSE_OK; } return (response == GTK_RESPONSE_OK); }
static VALUE fileinfo_has_attribute(VALUE self, VALUE attribute) { return CBOOL2RVAL(g_file_info_has_attribute(_SELF(self), RVAL2CSTR(attribute))); }
char * rb_uri_resolve_symlink (const char *uri, GError **error) { GFile *file = NULL; GFileInfo *file_info = NULL; int link_count = 0; char *result = NULL; const char *attr = G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET; GError *l_error = NULL; file = g_file_new_for_uri (uri); while (link_count < MAX_LINK_LEVEL) { GFile *parent; GFile *new_file; char *target; /* look for a symlink target */ file_info = g_file_query_info (file, attr, G_FILE_QUERY_INFO_NONE, NULL, &l_error); if (l_error != NULL) { /* argh */ result = g_file_get_uri (file); rb_debug ("error querying %s: %s", result, l_error->message); g_free (result); result = NULL; break; } else if (g_file_info_has_attribute (file_info, attr) == FALSE) { /* no symlink, so return the path */ result = g_file_get_uri (file); if (link_count > 0) { rb_debug ("resolved symlinks: %s -> %s", uri, result); } break; } /* resolve it and try again */ new_file = NULL; parent = g_file_get_parent (file); if (parent == NULL) { /* dang */ break; } target = g_file_info_get_attribute_as_string (file_info, attr); new_file = g_file_resolve_relative_path (parent, target); g_free (target); g_object_unref (parent); g_object_unref (file_info); file_info = NULL; g_object_unref (file); file = new_file; if (file == NULL) { /* dang */ break; } link_count++; } if (file != NULL) { g_object_unref (file); } if (file_info != NULL) { g_object_unref (file_info); } if (result == NULL && error == NULL) { rb_debug ("too many symlinks while resolving %s", uri); l_error = g_error_new (G_IO_ERROR, G_IO_ERROR_TOO_MANY_LINKS, _("Too many symlinks")); } if (l_error != NULL) { g_propagate_error (error, l_error); } return result; }
static gboolean validate_settings(signal_user_data_t *ud, GValue *settings, gint batch) { // Check to see if the dest file exists or is // already in the queue gchar *message, *dest; gint count, ii; gint titleindex; titleindex = ghb_settings_combo_int(settings, "title"); if (titleindex < 0) return FALSE; dest = ghb_settings_get_string(settings, "destination"); count = ghb_array_len(ud->queue); for (ii = 0; ii < count; ii++) { GValue *js; gchar *filename; js = ghb_array_get_nth(ud->queue, ii); filename = ghb_settings_get_string(js, "destination"); if (strcmp(dest, filename) == 0) { message = g_strdup_printf( "Destination: %s\n\n" "Another queued job has specified the same destination.\n" "Do you want to overwrite?", dest); if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite")) { g_free(filename); g_free(dest); g_free(message); return FALSE; } g_free(message); break; } g_free(filename); } gchar *destdir = g_path_get_dirname(dest); if (!g_file_test(destdir, G_FILE_TEST_IS_DIR)) { message = g_strdup_printf( "Destination: %s\n\n" "This is not a valid directory.", destdir); ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL); g_free(dest); g_free(message); g_free(destdir); return FALSE; } #if !defined(_WIN32) // This doesn't work properly on windows if (g_access(destdir, R_OK|W_OK) != 0) { message = g_strdup_printf( "Destination: %s\n\n" "Can not read or write the directory.", destdir); ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL); g_free(dest); g_free(message); g_free(destdir); return FALSE; } #endif if (!batch) { GFile *gfile; GFileInfo *info; guint64 size; gchar *resolved = ghb_resolve_symlink(destdir); gfile = g_file_new_for_path(resolved); info = g_file_query_filesystem_info(gfile, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, NULL, NULL); if (info != NULL) { if (g_file_info_has_attribute(info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE)) { size = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE); gint64 fsize = (guint64)10 * 1024 * 1024 * 1024; if (size < fsize) { message = g_strdup_printf( "Destination filesystem is almost full: %uM free\n\n" "Encode may be incomplete if you proceed.\n", (guint)(size / (1024L*1024L))); if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Proceed")) { g_free(dest); g_free(message); return FALSE; } g_free(message); } } g_object_unref(info); } g_object_unref(gfile); g_free(resolved); } g_free(destdir); if (g_file_test(dest, G_FILE_TEST_EXISTS)) { message = g_strdup_printf( "Destination: %s\n\n" "File already exists.\n" "Do you want to overwrite?", dest); if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite")) { g_free(dest); g_free(message); return FALSE; } g_free(message); g_unlink(dest); } g_free(dest); // Validate video quality is in a reasonable range if (!ghb_validate_vquality(settings)) { return FALSE; } // Validate audio settings if (!ghb_validate_audio(settings)) { return FALSE; } // Validate audio settings if (!ghb_validate_subtitles(settings)) { return FALSE; } // Validate video settings if (!ghb_validate_video(settings)) { return FALSE; } // Validate filter settings if (!ghb_validate_filters(settings)) { return FALSE; } return TRUE; }