/** * mate_vfs_uri_exists: * @uri: a uri. * * Check if the uri points to an existing entity. * * Return value: %TRUE if uri exists. */ gboolean mate_vfs_uri_exists (MateVFSURI *uri) { MateVFSFileInfo *info; MateVFSResult result; info = mate_vfs_file_info_new (); result = mate_vfs_get_file_info_uri (uri, info, MATE_VFS_FILE_INFO_DEFAULT); mate_vfs_file_info_unref (info); return result == MATE_VFS_OK; }
static void do_info (void) { char *from; MateVFSResult result; MateVFSFileInfo *info; from = get_fname (); info = mate_vfs_file_info_new (); result = mate_vfs_get_file_info ( from, info, MATE_VFS_FILE_INFO_GET_MIME_TYPE); if (show_if_error (result, "getting info on: ", from)) return; print_info (info); mate_vfs_file_info_unref (info); }
static void do_handleinfo (void) { const char *handlename = get_handle (); MateVFSResult result; MateVFSHandle *handle = lookup_file (handlename); MateVFSFileInfo *info; if (!handle) return; info = mate_vfs_file_info_new (); result = mate_vfs_get_file_info_from_handle (handle, info, MATE_VFS_FILE_INFO_GET_MIME_TYPE); if (show_if_error (result, "getting info from handle: ", handlename)) return; print_info (info); mate_vfs_file_info_unref (info); }
int main (int argc, char **argv) { MateVFSResult result; char *text_uri; MateVFSURI *src, *dest; MateVFSFileInfo *info; if (argc != 3) { printf ("Usage: %s <src> <dest>\n", argv[0]); return 1; } if (!mate_vfs_init ()) { fprintf (stderr, "Cannot initialize mate-vfs.\n"); return 1; } command_line_authentication_init (); text_uri = mate_vfs_make_uri_from_shell_arg (argv[1]); src = mate_vfs_uri_new (text_uri); g_free (text_uri); text_uri = mate_vfs_make_uri_from_shell_arg (argv[2]); dest = mate_vfs_uri_new (text_uri); g_free (text_uri); if (src == NULL || dest == NULL) { result = MATE_VFS_ERROR_INVALID_URI; goto out; } info = mate_vfs_file_info_new (); result = mate_vfs_get_file_info_uri (dest, info, MATE_VFS_FILE_INFO_DEFAULT); if (result != MATE_VFS_OK && result != MATE_VFS_ERROR_NOT_FOUND) { mate_vfs_file_info_unref (info); goto out; } /* If the target is a directory do not overwrite it but copy the source into the directory! (This is like cp does it) */ if (info->valid_fields & MATE_VFS_FILE_INFO_FIELDS_TYPE && info->type == MATE_VFS_FILE_TYPE_DIRECTORY) { char *name; MateVFSURI *new_dest; name = mate_vfs_uri_extract_short_path_name (src); new_dest = mate_vfs_uri_append_string (dest, name); mate_vfs_uri_unref (dest); g_free (name); dest = new_dest; } mate_vfs_file_info_unref (info); result = mate_vfs_xfer_uri (src, dest, MATE_VFS_XFER_RECURSIVE, MATE_VFS_XFER_ERROR_MODE_ABORT, MATE_VFS_XFER_OVERWRITE_MODE_REPLACE, NULL, NULL); out: if (src) { mate_vfs_uri_unref (src); } if (dest) { mate_vfs_uri_unref (dest); } if (result != MATE_VFS_OK) { fprintf (stderr, "Failed to copy %s to %s\nReason: %s\n", argv[1], argv[2], mate_vfs_result_to_string (result)); return 1; } return 0; }