static gboolean try_enumerate (GVfsBackend *backend, GVfsJobEnumerate *job, const char *filename, GFileAttributeMatcher *matcher, GFileQueryInfoFlags flags) { GFileInfo *info1, *info2; GList *l; g_print ("try_enumerate (%s)\n", filename); g_vfs_job_succeeded (G_VFS_JOB (job)); info1 = g_file_info_new (); info2 = g_file_info_new (); g_file_info_set_name (info1, "file1"); g_file_info_set_file_type (info1, G_FILE_TYPE_REGULAR); g_file_info_set_name (info2, "file2"); g_file_info_set_file_type (info2, G_FILE_TYPE_REGULAR); l = NULL; l = g_list_append (l, info1); l = g_list_append (l, info2); g_vfs_job_enumerate_add_infos (job, l); g_list_free (l); g_object_unref (info1); g_object_unref (info2); g_vfs_job_enumerate_done (job); return TRUE; }
static IdeProjectFile * create_file (IdeContext *context, GFile *file, GFileType file_type) { g_autofree gchar *path = NULL; g_autofree gchar *name = NULL; g_autoptr(GFileInfo) file_info = NULL; IdeVcs *vcs; GFile *workdir; g_assert (IDE_IS_CONTEXT (context)); g_assert (G_IS_FILE (file)); g_assert ((file_type == G_FILE_TYPE_DIRECTORY) || (file_type == G_FILE_TYPE_REGULAR)); vcs = ide_context_get_vcs (context); workdir = ide_vcs_get_working_directory (vcs); path = g_file_get_relative_path (workdir, file); name = g_file_get_basename (file); file_info = g_file_info_new (); g_file_info_set_file_type (file_info, file_type); g_file_info_set_name (file_info, name); g_file_info_set_display_name (file_info, name); return g_object_new (IDE_TYPE_PROJECT_FILE, "context", context, "file", file, "file-info", file_info, "path", path, "parent", NULL, NULL); }
static GFileInfo * create_root_file_info (GVfsBackendFtp *ftp) { GFileInfo *info; GIcon *icon; char *display_name; info = g_file_info_new (); g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); g_file_info_set_name (info, "/"); display_name = g_strdup_printf (_("/ on %s"), ftp->host_display_name); g_file_info_set_display_name (info, display_name); g_free (display_name); g_file_info_set_edit_name (info, "/"); g_file_info_set_content_type (info, "inode/directory"); g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE, "inode/directory"); icon = g_themed_icon_new ("folder-remote"); g_file_info_set_icon (info, icon); g_object_unref (icon); return info; }
static void recent_backend_add_info (RecentItem *item, GFileInfo *info) { g_assert (item != NULL); g_file_info_set_name (info, item->guid); g_file_info_set_display_name (info, item->display_name); g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI, item->uri); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, FALSE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE, FALSE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME, FALSE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH, FALSE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE, TRUE); }
static gboolean try_query_info (GVfsBackend *backend, GVfsJobQueryInfo *job, const char *filename, GFileQueryInfoFlags flags, GFileInfo *info, GFileAttributeMatcher *matcher) { if (is_root (filename)) { GIcon *icon; g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); g_file_info_set_name (info, "/"); g_file_info_set_display_name (info, g_vfs_backend_get_display_name (backend)); g_file_info_set_content_type (info, "inode/directory"); icon = g_vfs_backend_get_icon (backend); if (icon != NULL) g_file_info_set_icon (info, icon); g_vfs_job_succeeded (G_VFS_JOB (job)); } else update_cache (G_VFS_BACKEND_AFP_BROWSE (backend), G_VFS_JOB (job)->cancellable, query_info_cb, job); return TRUE; }
static void fill_info (GFileInfo *info, GVfsAfpVolumeData *vol_data, GVfsBackendAfpBrowse *afp_backend) { GIcon *icon; GMountSpec *mount_spec; char *uri; g_file_info_set_name (info, vol_data->name); g_file_info_set_display_name (info, vol_data->name); g_file_info_set_edit_name (info, vol_data->name); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_STANDARD_IS_VIRTUAL, TRUE); g_file_info_set_content_type (info, "inode/directory"); g_file_info_set_file_type (info, G_FILE_TYPE_MOUNTABLE); g_file_info_set_attribute_boolean (info, "afp::volume-password-protected", (vol_data->flags & 0x01)); icon = g_themed_icon_new_with_default_fallbacks ("folder-remote-afp"); g_file_info_set_icon (info, icon); g_object_unref (icon); icon = g_themed_icon_new_with_default_fallbacks ("folder-remote-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); mount_spec = g_mount_spec_new ("afp-volume"); g_mount_spec_set (mount_spec, "host", g_network_address_get_hostname (G_NETWORK_ADDRESS (afp_backend->addr))); g_mount_spec_set (mount_spec, "volume", vol_data->name); g_mount_spec_set (mount_spec, "user", afp_backend->logged_in_user); if (g_mount_tracker_has_mount_spec (afp_backend->mount_tracker, mount_spec)) { g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT, FALSE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT, TRUE); } else { g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT, TRUE); g_file_info_set_attribute_boolean(info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT, FALSE); } g_mount_spec_unref (mount_spec); uri = g_strdup_printf ("afp://%s/%s", g_network_address_get_hostname (G_NETWORK_ADDRESS (afp_backend->addr)), vol_data->name); g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI, uri); g_free (uri); }
gboolean add_file_to_mtree (GFile *file, const char *name, OstreeRepo *repo, OstreeMutableTree *mtree, GCancellable *cancellable, GError **error) { g_autoptr(GFileInfo) file_info = NULL; g_autoptr(GInputStream) raw_input = NULL; g_autoptr(GInputStream) input = NULL; guint64 length; g_autofree guchar *child_file_csum = NULL; g_autofree char *tmp_checksum = NULL; file_info = g_file_query_info (file, "standard::size", 0, cancellable, error); if (file_info == NULL) return FALSE; g_file_info_set_name (file_info, name); g_file_info_set_file_type (file_info, G_FILE_TYPE_REGULAR); g_file_info_set_attribute_uint32 (file_info, "unix::uid", 0); g_file_info_set_attribute_uint32 (file_info, "unix::gid", 0); g_file_info_set_attribute_uint32 (file_info, "unix::mode", 0100644); raw_input = (GInputStream *) g_file_read (file, cancellable, error); if (raw_input == NULL) return FALSE; if (!ostree_raw_file_to_content_stream (raw_input, file_info, NULL, &input, &length, cancellable, error)) return FALSE; if (!ostree_repo_write_content (repo, NULL, input, length, &child_file_csum, cancellable, error)) return FALSE; tmp_checksum = ostree_checksum_from_bytes (child_file_csum); if (!ostree_mutable_tree_replace_file (mtree, name, tmp_checksum, error)) return FALSE; return TRUE; }
static void build_context (GbProjectTreeBuilder *self, IdeTreeNode *node) { g_autoptr(GbProjectFile) item = NULL; g_autoptr(GFileInfo) file_info = NULL; g_autofree gchar *name = NULL; IdeTreeNode *child; IdeContext *context; IdeProject *project; IdeVcs *vcs; GFile *workdir; g_return_if_fail (GB_IS_PROJECT_TREE_BUILDER (self)); g_return_if_fail (IDE_IS_TREE_NODE (node)); context = IDE_CONTEXT (ide_tree_node_get_item (node)); vcs = ide_context_get_vcs (context); workdir = ide_vcs_get_working_directory (vcs); project = ide_context_get_project (context); file_info = g_file_info_new (); g_file_info_set_file_type (file_info, G_FILE_TYPE_DIRECTORY); name = g_file_get_basename (workdir); g_file_info_set_name (file_info, name); g_file_info_set_display_name (file_info, name); item = g_object_new (GB_TYPE_PROJECT_FILE, "file", workdir, "file-info", file_info, NULL); child = g_object_new (IDE_TYPE_TREE_NODE, "item", item, "icon-name", "folder-symbolic", NULL); g_object_bind_property (project, "name", child, "text", G_BINDING_SYNC_CREATE); ide_tree_node_append (node, child); }
static void trash_backend_enumerate_root (GVfsBackendTrash *backend, GVfsJobEnumerate *job, GFileAttributeMatcher *attribute_matcher, GFileQueryInfoFlags flags) { GList *items, *node; g_vfs_job_succeeded (G_VFS_JOB (job)); items = trash_root_get_items (backend->root); for (node = items; node; node = node->next) { TrashItem *item = node->data; GFileInfo *info; info = g_file_query_info (trash_item_get_file (item), job->attributes, flags, G_VFS_JOB (job)->cancellable, NULL); if (info) { g_file_info_set_attribute_mask (info, attribute_matcher); g_file_info_set_name (info, trash_item_get_escaped_name (item)); trash_backend_add_info (item, info, TRUE); g_vfs_job_enumerate_add_info (job, info); g_object_unref (info); } trash_item_unref (item); } g_vfs_job_enumerate_done (job); g_list_free (items); }
static GFileInfo * g_resource_file_query_info (GFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error) { GResourceFile *resource = G_RESOURCE_FILE (file); GError *my_error = NULL; GFileInfo *info; GFileAttributeMatcher *matcher; gboolean res; gsize size; guint32 resource_flags; char **children; gboolean is_dir; char *base; is_dir = FALSE; children = g_resources_enumerate_children (resource->path, 0, NULL); if (children != NULL) { g_strfreev (children); is_dir = TRUE; } /* root is always there */ if (strcmp ("/", resource->path) == 0) is_dir = TRUE; if (!is_dir) { res = g_resources_get_info (resource->path, 0, &size, &resource_flags, &my_error); if (!res) { if (g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, _("The resource at '%s' does not exist"), resource->path); } else g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, my_error->message); g_clear_error (&my_error); return FALSE; } } matcher = g_file_attribute_matcher_new (attributes); info = g_file_info_new (); base = g_resource_file_get_basename (file); g_file_info_set_name (info, base); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_READ, TRUE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_WRITE, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_EXECUTE, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH, FALSE); if (is_dir) { g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); } else { GBytes *bytes; char *content_type; g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); g_file_info_set_size (info, size); if ((_g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE) || ((~resource_flags & G_RESOURCE_FLAGS_COMPRESSED) && _g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE))) && (bytes = g_resources_lookup_data (resource->path, 0, NULL))) { const guchar *data; gsize data_size; data = g_bytes_get_data (bytes, &data_size); content_type = g_content_type_guess (base, data, data_size, NULL); g_bytes_unref (bytes); } else content_type = NULL; if (content_type) { _g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE, content_type); _g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE, content_type); g_free (content_type); } } g_free (base); g_file_attribute_matcher_unref (matcher); return info; }
static gboolean fm_file_info_job_run(FmJob* fmjob) { GList* l; FmFileInfoJob* job = (FmFileInfoJob*)fmjob; GError* err = NULL; if(job->file_infos == NULL) return FALSE; for(l = fm_file_info_list_peek_head_link(job->file_infos); !fm_job_is_cancelled(fmjob) && l;) { FmFileInfo* fi = (FmFileInfo*)l->data; GList* next = l->next; FmPath* path = fm_file_info_get_path(fi); if(job->current) fm_path_unref(job->current); job->current = fm_path_ref(path); if(fm_path_is_native(path)) { char* path_str = fm_path_to_str(path); if(!_fm_file_info_job_get_info_for_native_file(fmjob, fi, path_str, &err)) { FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MILD); g_error_free(err); err = NULL; if(act == FM_JOB_RETRY) { g_free(path_str); continue; /* retry */ } fm_file_info_list_delete_link(job->file_infos, l); /* also calls unref */ } else if(G_UNLIKELY(job->flags & FM_FILE_INFO_JOB_EMIT_FOR_EACH_FILE)) fm_job_call_main_thread(fmjob, _emit_current_file, fi); g_free(path_str); /* recursively set display names for path parents */ _check_native_display_names(fm_path_get_parent(path)); } else { GFile* gf; gf = fm_path_to_gfile(path); if(!_fm_file_info_job_get_info_for_gfile(fmjob, fi, gf, &err)) { if(err->domain == G_IO_ERROR && err->code == G_IO_ERROR_NOT_MOUNTED) { GFileInfo *inf; /* location by link isn't mounted; unfortunately we cannot launch a target if we don't know what kind of target we have; lets make a simplest directory-kind GFIleInfo */ /* FIXME: this may be dirty a bit */ g_error_free(err); err = NULL; inf = g_file_info_new(); g_file_info_set_file_type(inf, G_FILE_TYPE_DIRECTORY); g_file_info_set_name(inf, fm_path_get_basename(path)); g_file_info_set_display_name(inf, fm_path_get_basename(path)); fm_file_info_set_from_g_file_data(fi, gf, inf); g_object_unref(inf); } else { FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MILD); g_error_free(err); err = NULL; if(act == FM_JOB_RETRY) { g_object_unref(gf); continue; /* retry */ } fm_file_info_list_delete_link(job->file_infos, l); /* also calls unref */ goto _next; } } else if(G_UNLIKELY(job->flags & FM_FILE_INFO_JOB_EMIT_FOR_EACH_FILE)) fm_job_call_main_thread(fmjob, _emit_current_file, fi); /* recursively set display names for path parents */ _check_gfile_display_names(fm_path_get_parent(path), gf); _next: g_object_unref(gf); } l = next; } return TRUE; }
static gboolean trash_backend_query_info (GVfsBackend *vfs_backend, GVfsJobQueryInfo *job, const char *filename, GFileQueryInfoFlags flags, GFileInfo *info, GFileAttributeMatcher *matcher) { GVfsBackendTrash *backend = G_VFS_BACKEND_TRASH (vfs_backend); g_assert (filename[0] == '/'); if (filename[1]) { GError *error = NULL; gboolean is_toplevel; TrashItem *item; GFile *real; real = trash_backend_get_file (backend, filename, &item, &is_toplevel, &error); if (real) { GFileInfo *real_info; real_info = g_file_query_info (real, job->attributes, flags, G_VFS_JOB (job)->cancellable, &error); g_object_unref (real); if (real_info) { g_file_info_copy_into (real_info, info); trash_backend_add_info (item, info, is_toplevel); g_vfs_job_succeeded (G_VFS_JOB (job)); trash_item_unref (item); g_object_unref (real_info); return TRUE; } trash_item_unref (item); } g_vfs_job_failed_from_error (G_VFS_JOB (job), error); g_error_free (error); } else { GIcon *icon; int n_items; n_items = trash_root_get_n_items (backend->root); g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); g_file_info_set_name (info, "/"); /* Translators: this is the display name of the backend */ g_file_info_set_display_name (info, _("Trash")); g_file_info_set_content_type (info, "inode/directory"); icon = g_themed_icon_new (n_items ? "user-trash-full" : "user-trash"); g_file_info_set_icon (info, icon); g_object_unref (icon); icon = g_themed_icon_new (n_items ? "user-trash-full-symbolic" : "user-trash-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT, n_items); g_vfs_job_succeeded (G_VFS_JOB (job)); } return TRUE; }
static gboolean recent_backend_query_info (GVfsBackend *vfs_backend, GVfsJobQueryInfo *job, const char *filename, GFileQueryInfoFlags flags, GFileInfo *info, GFileAttributeMatcher *matcher) { GVfsBackendRecent *backend = G_VFS_BACKEND_RECENT (vfs_backend); g_assert (filename[0] == '/'); if (filename[1]) { GError *error = NULL; RecentItem *item = NULL; GFile *real; real = recent_backend_get_file (backend, filename, &item, &error); if (real) { GFileInfo *real_info; real_info = g_file_query_info (real, job->attributes, flags, G_VFS_JOB (job)->cancellable, &error); g_object_unref (real); if (real_info) { g_file_info_copy_into (real_info, info); recent_backend_add_info (item, info); g_vfs_job_succeeded (G_VFS_JOB (job)); g_object_unref (real_info); return TRUE; } } g_vfs_job_failed_from_error (G_VFS_JOB (job), error); g_error_free (error); } else { GIcon *icon; g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); g_file_info_set_name (info, "/"); /* Translators: this is the display name of the backend */ g_file_info_set_display_name (info, _("Recent")); g_file_info_set_content_type (info, "inode/directory"); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, FALSE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE, TRUE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH, FALSE); icon = g_themed_icon_new ("document-open-recent"); g_file_info_set_icon (info, icon); g_object_unref (icon); icon = g_themed_icon_new ("document-open-recent-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); g_vfs_job_succeeded (G_VFS_JOB (job)); } return TRUE; }
static GFileInfo * g_vfs_ftp_dir_cache_funcs_lookup_uncached (GVfsFtpTask * task, const GVfsFtpFile *file) { GFileInfo *info; char **reply; if (g_vfs_ftp_file_is_root (file)) return create_root_file_info (task->backend); /* the directory cache fails when the parent directory of the file is not readable. * This cannot happen on Unix, but it can happen on FTP. * In this case we try to figure out as much as possible about the file (does it even exist?) * using standard ftp commands. */ if (g_vfs_ftp_task_send (task, 0, "CWD %s", g_vfs_ftp_file_get_ftp_path (file))) { char *tmp; info = g_file_info_new (); tmp = g_path_get_basename (g_vfs_ftp_file_get_gvfs_path (file)); g_file_info_set_name (info, tmp); g_free (tmp); gvfs_file_info_populate_default (info, g_vfs_ftp_file_get_gvfs_path (file), G_FILE_TYPE_DIRECTORY); g_file_info_set_is_hidden (info, TRUE); return info; } g_vfs_ftp_task_clear_error (task); if (g_vfs_ftp_task_send_and_check (task, 0, NULL, NULL, &reply, "SIZE %s", g_vfs_ftp_file_get_ftp_path (file))) { char *tmp; info = g_file_info_new (); tmp = g_path_get_basename (g_vfs_ftp_file_get_gvfs_path (file)); g_file_info_set_name (info, tmp); g_free (tmp); gvfs_file_info_populate_default (info, g_vfs_ftp_file_get_gvfs_path (file), G_FILE_TYPE_REGULAR); g_file_info_set_size (info, g_ascii_strtoull (reply[0] + 4, NULL, 0)); g_strfreev (reply); g_file_info_set_is_hidden (info, TRUE); return info; } g_vfs_ftp_task_clear_error (task); /* note that there might still be a file/directory, we just have * no way to figure this out (in particular on ftp servers that * don't support SIZE. * If you have ways to improve file detection, patches are welcome. */ return NULL; }
static gboolean fm_dir_list_job_run_posix(FmDirListJob* job) { FmJob* fmjob = FM_JOB(job); FmFileInfo* fi; GError *err = NULL; char* path_str; GDir* dir; path_str = fm_path_to_str(job->dir_path); fi = _new_info_for_native_file(job, job->dir_path, path_str, NULL); if(fi) { if(! fm_file_info_is_dir(fi)) { err = g_error_new(G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY, _("The specified directory '%s' is not valid"), path_str); fm_file_info_unref(fi); fm_job_emit_error(fmjob, err, FM_JOB_ERROR_CRITICAL); g_error_free(err); g_free(path_str); return FALSE; } job->dir_fi = fi; } else { err = g_error_new(G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY, _("The specified directory '%s' is not valid"), path_str); fm_job_emit_error(fmjob, err, FM_JOB_ERROR_CRITICAL); g_error_free(err); g_free(path_str); return FALSE; } dir = g_dir_open(path_str, 0, &err); if( dir ) { const char* name; GString* fpath = g_string_sized_new(4096); int dir_len = strlen(path_str); g_string_append_len(fpath, path_str, dir_len); if(fpath->str[dir_len-1] != '/') { g_string_append_c(fpath, '/'); ++dir_len; } while( ! fm_job_is_cancelled(fmjob) && (name = g_dir_read_name(dir)) ) { FmPath* new_path; g_string_truncate(fpath, dir_len); g_string_append(fpath, name); if(job->flags & FM_DIR_LIST_JOB_DIR_ONLY) /* if we only want directories */ { struct stat st; /* FIXME: this results in an additional stat() call, which is inefficient */ if(stat(fpath->str, &st) == -1 || !S_ISDIR(st.st_mode)) continue; } new_path = fm_path_new_child(job->dir_path, name); _retry: fi = _new_info_for_native_file(job, new_path, fpath->str, &err); if (fi == NULL) /* we got a damaged file */ { FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MILD); GFile *gf; GFileInfo *inf; gchar *disp_basename; g_error_free(err); err = NULL; if(act == FM_JOB_RETRY) goto _retry; /* bug #3615271: Damaged mountpoint isn't shown let make a simple file info then */ inf = g_file_info_new(); gf = fm_path_to_gfile(new_path); g_file_info_set_file_type(inf, G_FILE_TYPE_UNKNOWN); g_file_info_set_name(inf, name); disp_basename = g_filename_display_basename(fpath->str); g_file_info_set_display_name(inf, disp_basename); g_free(disp_basename); g_file_info_set_content_type(inf, "inode/x-corrupted"); fi = fm_file_info_new_from_g_file_data(gf, inf, new_path); g_object_unref(inf); g_object_unref(gf); } fm_dir_list_job_add_found_file(job, fi); fm_file_info_unref(fi); fm_path_unref(new_path); } g_string_free(fpath, TRUE); g_dir_close(dir); } else { fm_job_emit_error(fmjob, err, FM_JOB_ERROR_CRITICAL); g_error_free(err); } g_free(path_str); return TRUE; }
void ide_project_files_add_file (IdeProjectFiles *self, IdeProjectFile *file) { IdeProjectItem *item = (IdeProjectItem *)self; g_autoptr(GFile) parent = NULL; g_autofree gchar *path = NULL; IdeContext *context; IdeVcs *vcs; GFile *workdir; GFile *gfile; gchar **parts; gsize i; g_return_if_fail (IDE_IS_PROJECT_FILES (self)); g_return_if_fail (IDE_IS_PROJECT_FILE (file)); context = ide_object_get_context (IDE_OBJECT (self)); vcs = ide_context_get_vcs (context); workdir = ide_vcs_get_working_directory (vcs); gfile = ide_project_file_get_file (file); parent = g_file_get_parent (gfile); path = g_file_get_relative_path (workdir, parent); if (path == NULL) { ide_project_item_append (IDE_PROJECT_ITEM (self), IDE_PROJECT_ITEM (file)); return; } parts = g_strsplit (path, G_DIR_SEPARATOR_S, 0); for (i = 0; parts [i]; i++) { IdeProjectItem *found; found = ide_project_files_find_child (item, parts [i]); if (found == NULL) { g_autoptr(GFileInfo) file_info = NULL; g_autofree gchar *child_path = NULL; IdeProjectItem *child; const gchar *item_path; g_autoptr(GFile) item_file = NULL; file_info = g_file_info_new (); g_file_info_set_file_type (file_info, G_FILE_TYPE_DIRECTORY); g_file_info_set_display_name (file_info, parts [i]); g_file_info_set_name (file_info, parts [i]); item_path = ide_project_file_get_path (IDE_PROJECT_FILE (item)); child_path = g_strjoin (G_DIR_SEPARATOR_S, item_path, parts [i], NULL); item_file = g_file_get_child (workdir, child_path); child = g_object_new (IDE_TYPE_PROJECT_FILE, "context", context, "parent", item, "path", path, "file", item_file, "file-info", file_info, NULL); ide_project_item_append (item, child); item = child; } else { item = found; } } ide_project_item_append (item, IDE_PROJECT_ITEM (file)); g_strfreev (parts); }
static gboolean g_vfs_ftp_dir_cache_funcs_process (GInputStream * stream, int debug_id, const GVfsFtpFile * dir, GVfsFtpDirCacheEntry *entry, gboolean is_unix, GCancellable * cancellable, GError ** error) { struct list_state state = { NULL, }; GDataInputStream *data; GFileInfo *info; int type; GVfsFtpFile *file; char *line, *s; gsize length; /* protect against code reorg - in current code, error never is NULL */ g_assert (error != NULL); g_assert (*error == NULL); data = g_data_input_stream_new (stream); /* we use LF only, because the mozilla code can handle lines ending in CR */ g_data_input_stream_set_newline_type (data, G_DATA_STREAM_NEWLINE_TYPE_LF); while ((line = g_data_input_stream_read_line (data, &length, cancellable, error))) { struct list_result result = { 0, }; GFileType file_type = G_FILE_TYPE_UNKNOWN; GTimeVal tv = { 0, 0 }; /* strip trailing \r - ParseFTPList only removes it if the line ends in \r\n, * but we stripped the \n already. */ if (length > 0 && line[length - 1] == '\r') line[--length] = '\0'; g_debug ("<<%2d << %s\n", debug_id, line); type = ParseFTPList (line, &state, &result); if (type != 'd' && type != 'f' && type != 'l') { g_free (line); continue; } /* don't list . and .. directories * Let's hope they're not important files on some ftp servers */ if (result.fe_fnlen == 1 && result.fe_fname[0] == '.') { g_free (line); continue; } if (result.fe_fnlen == 2 && result.fe_fname[0] == '.' && result.fe_fname[1] == '.') { g_free (line); continue; } s = g_strndup (result.fe_fname, result.fe_fnlen); file = g_vfs_ftp_file_new_child (dir, s, NULL); g_free (s); if (file == NULL) { g_debug ("# invalid filename, skipping"); g_free (line); continue; } info = g_file_info_new (); s = g_path_get_basename (g_vfs_ftp_file_get_gvfs_path (file)); g_file_info_set_name (info, s); g_free (s); if (type == 'l') { char *link; link = g_strndup (result.fe_lname, result.fe_lnlen); g_file_info_set_symlink_target (info, link); g_file_info_set_is_symlink (info, TRUE); g_free (link); } g_file_info_set_size (info, g_ascii_strtoull (result.fe_size, NULL, 10)); /* If unix format then parse the attributes */ if (state.lstyle == 'U') { char file_mode[10], uid[64], gid[64]; guint32 mode; /* POSIX ls -l form: mode, links, owner, group */ if (sscanf(line, "%10c %*u %63s %63s", file_mode, uid, gid) == 3) { if (g_vfs_ftp_parse_mode (file_mode, &mode, &file_type)) { g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE, mode); g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_USER, uid); g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_GROUP, gid); } } else g_debug ("# unknown listing format\n"); } if (file_type == G_FILE_TYPE_UNKNOWN) { file_type = type == 'f' ? G_FILE_TYPE_REGULAR : type == 'l' ? G_FILE_TYPE_SYMBOLIC_LINK : G_FILE_TYPE_DIRECTORY; } gvfs_file_info_populate_default (info, g_vfs_ftp_file_get_gvfs_path (file), file_type); if (is_unix) g_file_info_set_is_hidden (info, result.fe_fnlen > 0 && result.fe_fname[0] == '.'); /* Workaround: * result.fetime.tm_year contains actual year instead of offset-from-1900, * which mktime expects. */ if (result.fe_time.tm_year >= 1900) result.fe_time.tm_year -= 1900; tv.tv_sec = mktime (&result.fe_time); if (tv.tv_sec != -1) g_file_info_set_modification_time (info, &tv); g_vfs_ftp_dir_cache_entry_add (entry, file, info); g_free (line); } g_object_unref (data); return *error != NULL; }
static gboolean fl_parser_fill_file_info (GFileInfo *info, const char **attr) { gint i; for (i = 0; attr[i]; ++i) { const gchar *name; const gchar *value; name = attr[i]; value = attr[++i]; if (strcmp (name, "name") == 0) { char *display_name; /* Apparently someone decided it was a good idea * to send name="" mem-type="MMC" */ if (!value || strcmp (value, "") == 0) { return FALSE; } g_file_info_set_name (info, value); display_name = g_filename_display_name (value); g_file_info_set_display_name (info, display_name); d(g_print ("Name: '%s'\n", display_name)); g_free (display_name); } else if (strcmp (name, "size") == 0) { g_file_info_set_size (info, strtoll (value, NULL, 10)); d(g_print ("Size: '%"G_GINT64_FORMAT"'\n", g_file_info_get_size (info))); } else if (strcmp (name, "modified") == 0) { GTimeVal time; if (g_time_val_from_iso8601 (value, &time) == FALSE) continue; g_file_info_set_modification_time (info, &time); d(g_print ("Modified: '%s' = '%d'\n", value, (int)time.tv_sec)); } else if (strcmp (name, "created") == 0) { GTimeVal time; if (g_time_val_from_iso8601 (value, &time) == FALSE) continue; g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CREATED, time.tv_sec); g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_CREATED_USEC, time.tv_usec); d(g_print ("Created: '%s' = '%d'\n", value, (int)time.tv_sec)); } else if (strcmp (name, "accessed") == 0) { GTimeVal time; if (g_time_val_from_iso8601 (value, &time) == FALSE) continue; g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_ACCESS, time.tv_sec); g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_ACCESS_USEC, time.tv_usec); d(g_print ("Accessed: '%s' = '%d'\n", value, (int)time.tv_sec)); } else if (strcmp (name, "user-perm") == 0) { /* The permissions don't map well to unix semantics, * since the user is most likely not the same on both * sides. We map the user permissions to "other" on the * local side. D is treated as write, otherwise files * can't be deleted through the module, even if it * should be possible. */ if (strstr (value, "R")) { g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ, TRUE); } if (strstr (value, "W") || strstr (value, "D")) { g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, TRUE); } } else if (strcmp (name, "group-perm") == 0) { /* Ignore for now */ d(g_print ("Group permissions: '%s'\n", value)); } else if (strcmp (name, "other-perm") == 0) { /* Ignore for now */ d(g_print ("Other permissions: '%s'\n", value)); } else if (strcmp (name, "owner") == 0) { /* Ignore for now */ d(g_print ("Owner: '%s'\n", value)); } else if (strcmp (name, "group") == 0) { /* Ignore for now */ d(g_print ("Group: '%s'\n", value)); } else if (strcmp (name, "type") == 0) { g_file_info_set_content_type (info, value); d(g_print ("Mime-Type: '%s'\n", value)); } else if (strcmp (name, "xml:lang") == 0) { d(g_print ("Lang: '%s'\n", value)); } else if (strcmp (name, "mem-type") == 0) { guint device; if (value == NULL || value[0] == '\0') continue; device = om_mem_type_id_from_string (value); g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_RDEV, device); d(g_print ("Mem-Type: '%s' (%d)\n", value, device)); } else { d(g_print ("Unknown Attribute: %s = %s\n", name, value)); } } if (g_file_info_get_name (info) == NULL) { /* Required attribute */ /* Set error */ return FALSE; } return TRUE; }