/** * mate_vfs_move: * @old_text_uri: string representing the source file location. * @new_text_uri: string representing the destination file location. * @force_replace: if %TRUE, perform the operation even if it unlinks an existing * file at @new_text_uri. * * Move a file from @old_text_uri to @new_text_uri. This will only work * if @old_text_uri and @new_text_uri are on the same file system. Otherwise, * it is necessary to use the more general mate_vfs_xfer_uri() function. * * Return value: an integer representing the result of the operation. */ MateVFSResult mate_vfs_move (const gchar *old_text_uri, const gchar *new_text_uri, gboolean force_replace) { MateVFSURI *old_uri, *new_uri; MateVFSResult retval; g_return_val_if_fail (old_text_uri != NULL, MATE_VFS_ERROR_BAD_PARAMETERS); g_return_val_if_fail (new_text_uri != NULL, MATE_VFS_ERROR_BAD_PARAMETERS); old_uri = mate_vfs_uri_new (old_text_uri); if (old_uri == NULL) return MATE_VFS_ERROR_INVALID_URI; new_uri = mate_vfs_uri_new (new_text_uri); if (new_uri == NULL) { mate_vfs_uri_unref (old_uri); return MATE_VFS_ERROR_INVALID_URI; } retval = mate_vfs_move_uri (old_uri, new_uri, force_replace); mate_vfs_uri_unref (old_uri); mate_vfs_uri_unref (new_uri); return retval; }
/** * mate_vfs_check_same_fs: * @source: path to a file. * @target: path to another file. * @same_fs_return: pointer to a boolean variable which will be set to %TRUE * on return if @source and @target are on the same file system. * * Check if @source and @target are on the same file system. * * Return value: an integer representing the result of the operation. */ MateVFSResult mate_vfs_check_same_fs (const gchar *source, const gchar *target, gboolean *same_fs_return) { MateVFSURI *a_uri, *b_uri; MateVFSResult retval; g_return_val_if_fail (source != NULL, MATE_VFS_ERROR_BAD_PARAMETERS); g_return_val_if_fail (target != NULL, MATE_VFS_ERROR_BAD_PARAMETERS); g_return_val_if_fail (same_fs_return != NULL, MATE_VFS_ERROR_BAD_PARAMETERS); *same_fs_return = FALSE; a_uri = mate_vfs_uri_new (source); if (a_uri == NULL) return MATE_VFS_ERROR_INVALID_URI; b_uri = mate_vfs_uri_new (target); if (b_uri == NULL) { mate_vfs_uri_unref (a_uri); return MATE_VFS_ERROR_INVALID_URI; } retval = mate_vfs_check_same_fs_uris (a_uri, b_uri, same_fs_return); mate_vfs_uri_unref (a_uri); mate_vfs_uri_unref (b_uri); return retval; }
int main (int argc, char **argv) { MateVFSResult result; MateVFSURI *uri; gchar *text_uri; if (argc != 2) { printf ("Usage: %s <uri>\n", argv[0]); return 1; } if (! mate_vfs_init ()) { fprintf (stderr, "Cannot initialize mate-vfs.\n"); return 1; } uri = mate_vfs_uri_new (argv[1]); if (uri == NULL) { fprintf (stderr, "URI not valid.\n"); return 1; } text_uri = mate_vfs_uri_to_string (uri, MATE_VFS_URI_HIDE_NONE); result = mate_vfs_unlink (text_uri); show_result (result, "unlink", text_uri); g_free (text_uri); return 0; }
/** * mate_vfs_monitor_add: * @handle: after the call, @handle will be a pointer to an operation handle. * @text_uri: string representing the uri to monitor. * @monitor_type: add a directory or file monitor. * @callback: function to call when the monitor is tripped. * @user_data: data to pass to @callback. * * Watch the file or directory at @text_uri for changes (or the creation/deletion of the file) * and call @callback when there is a change. If a directory monitor is added, @callback is * notified when any file in the directory changes. * * Return value: an integer representing the result of the operation. */ MateVFSResult mate_vfs_monitor_add (MateVFSMonitorHandle **handle, const gchar *text_uri, MateVFSMonitorType monitor_type, MateVFSMonitorCallback callback, gpointer user_data) { MateVFSURI *uri; MateVFSResult result; g_return_val_if_fail (handle != NULL, MATE_VFS_ERROR_BAD_PARAMETERS); *handle = NULL; g_return_val_if_fail (text_uri != NULL, MATE_VFS_ERROR_BAD_PARAMETERS); uri = mate_vfs_uri_new (text_uri); if (uri == NULL) { return MATE_VFS_ERROR_INVALID_URI; } if (!VFS_METHOD_HAS_FUNC(uri->method, monitor_add)) { mate_vfs_uri_unref (uri); return MATE_VFS_ERROR_NOT_SUPPORTED; } result = _mate_vfs_monitor_do_add (uri->method, handle, uri, monitor_type, callback, user_data); mate_vfs_uri_unref (uri); return result; }
static void ih_not_missing_callback (ih_sub_t *sub) { gchar *fullpath, *info_uri_str; MateVFSURI *info_uri; MateVFSMonitorEventType gevent; guint32 mask; if (sub->filename) { fullpath = g_strdup_printf ("%s/%s", sub->dirname, sub->filename); if (!g_file_test (fullpath, G_FILE_TEST_EXISTS)) { g_free (fullpath); return; } mask = IN_CREATE; } else { fullpath = g_strdup_printf ("%s/", sub->dirname); mask = IN_CREATE|IN_ISDIR; } gevent = ih_mask_to_EventType (mask); info_uri_str = mate_vfs_get_uri_from_local_path (fullpath); info_uri = mate_vfs_uri_new (info_uri_str); g_free (info_uri_str); mate_vfs_monitor_callback ((MateVFSMethodHandle *)sub, info_uri, gevent); mate_vfs_uri_unref (info_uri); g_free(fullpath); }
static MateVFSURI * translate_uri (MateVFSURI *uri) { MateVFSURI *translated_uri; char *uri_text; char *translated_uri_text; char *no_method; uri_text = mate_vfs_uri_to_string (uri, MATE_VFS_URI_HIDE_NONE); no_method = strchr (uri_text, ':'); if (test_method_name != NULL) { translated_uri_text = g_strconcat ((char *)test_method_name, no_method, NULL); } else { translated_uri_text = NULL; } if (translated_uri_text != NULL) { translated_uri = mate_vfs_uri_new (translated_uri_text); } else { translated_uri = NULL; } g_free (translated_uri_text); g_free (uri_text); return translated_uri; }
static void do_findtrash (void) { char *from; char *uri_as_string; MateVFSResult result; MateVFSURI *from_uri; MateVFSURI *result_vfs_uri; from = get_fname (); from_uri = mate_vfs_uri_new (from); result = mate_vfs_find_directory (from_uri, MATE_VFS_DIRECTORY_KIND_TRASH, &result_vfs_uri, TRUE, TRUE, 0777); if (result != MATE_VFS_OK) { fprintf (stdout, "couldn't find or create trash there, error code %d", result); } else { uri_as_string = mate_vfs_uri_to_string (result_vfs_uri, MATE_VFS_URI_HIDE_NONE); fprintf (stdout, "trash found or created here: %s", uri_as_string); g_free (uri_as_string); } mate_vfs_uri_unref (from_uri); mate_vfs_uri_unref (result_vfs_uri); }
/* Note that, while this initialized mate-vfs, it does * not guarentee that mate-vfs actually loads and initializes * the modules in question */ int main (int argc, char **argv) { int i; GModule *module; TestFunc test_func; gboolean result; gboolean running_result; make_asserts_break ("GLib"); make_asserts_break ("MateVFS"); /* Initialize the libraries we use. */ mate_vfs_init (); running_result = TRUE; for (i=0 ; self_test_modules[i] != NULL ; i++) { char *module_path; char *dummy_uri_string; MateVFSURI *uri; printf ("Module self-test: '%s'\n", self_test_modules[i]); module_path = g_module_build_path (MODULES_PATH, self_test_modules[i]); module = g_module_open (module_path, G_MODULE_BIND_LAZY); g_free (module_path); module_path = NULL; if (module == NULL) { fprintf (stderr, "Couldn't load module '%s'\n", self_test_modules[i]); continue; } g_module_symbol (module, "vfs_module_self_test", (gpointer *) &test_func); if (test_func == NULL) { fprintf (stderr, "Module had no self-test func '%s'\n", self_test_modules[i]); continue; } dummy_uri_string = g_strdup_printf ("%s:///", self_test_modules[i]); /* force normal initializing of the module by creating a URI * for that scheme */ uri = mate_vfs_uri_new (dummy_uri_string); mate_vfs_uri_unref (uri); g_free (dummy_uri_string); result = test_func(); fprintf (stderr, "%s: %s\n", self_test_modules[i], result ? "PASS" : "FAIL"); running_result = running_result && result; } exit (running_result ? 0 : -1); }
int main (int argc, char **argv) { MateVFSResult result; MateVFSHandle *handle; gchar buffer[1024]; MateVFSFileSize bytes_read; MateVFSURI *uri; gchar *text_uri; if (argc != 2) { printf ("Usage: %s <uri>\n", argv[0]); return 1; } if (! mate_vfs_init ()) { fprintf (stderr, "Cannot initialize mate-vfs.\n"); return 1; } uri = mate_vfs_uri_new (argv[1]); if (uri == NULL) { fprintf (stderr, "URI not valid.\n"); return 1; } text_uri = mate_vfs_uri_to_string (uri, MATE_VFS_URI_HIDE_NONE); result = mate_vfs_open_uri (&handle, uri, MATE_VFS_OPEN_WRITE); show_result (result, "open", text_uri); while( result==MATE_VFS_OK && !feof(stdin)) { MateVFSFileSize temp; bytes_read = fread(buffer, 1, sizeof buffer - 1, stdin); if(!bytes_read) break; buffer[bytes_read] = 0; result = mate_vfs_write (handle, buffer, bytes_read, &temp); show_result (result, "write", text_uri); } result = mate_vfs_close (handle); show_result (result, "close", text_uri); g_free (text_uri); return 0; }
/** * mate_vfs_truncate: * @text_uri: string representing the file to be truncated. * @length: length of the new file at @text_uri. * * Truncate the file at @text_uri to @length bytes. * * Return value: an integer representing the result of the operation. */ MateVFSResult mate_vfs_truncate (const char *text_uri, MateVFSFileSize length) { MateVFSURI *uri; MateVFSResult result; uri = mate_vfs_uri_new (text_uri); if (uri == NULL) return MATE_VFS_ERROR_NOT_SUPPORTED; result = mate_vfs_truncate_uri(uri, length); mate_vfs_uri_unref (uri); return result; }
/** * mate_vfs_set_file_info: * @text_uri: string representing the file location. * @info: information that must be set for the file. * @mask: bit mask representing which fields of @info need to be set. * * Set file information for @uri; only the information for which the * corresponding bit in @mask is set is actually modified. * * <note> * @info's %valid_fields is not required to contain the * #MateVFSFileInfoFields corresponding to the specified * #MateVFSSetFileInfoMask fields of @mask. It * is assumed that the @info fields referenced by @mask * are valid. * </note> * * Return value: an integer representing the result of the operation. */ MateVFSResult mate_vfs_set_file_info (const gchar *text_uri, MateVFSFileInfo *info, MateVFSSetFileInfoMask mask) { MateVFSURI *uri; MateVFSResult result; uri = mate_vfs_uri_new (text_uri); if (uri == NULL) return MATE_VFS_ERROR_INVALID_URI; result = mate_vfs_set_file_info_uri (uri, info, mask); mate_vfs_uri_unref (uri); return result; }
/** * mate_vfs_get_file_info: * @text_uri: uri of the file for which information will be retrieved. * @info: pointer to a #MateVFSFileInfo object that will hold the information * for the file on return. * @options: options for retrieving file information. * * Retrieve information about @text_uri. The information will be stored in * @info. * * Return value: an integer representing the result of the operation. */ MateVFSResult mate_vfs_get_file_info (const gchar *text_uri, MateVFSFileInfo *info, MateVFSFileInfoOptions options) { MateVFSURI *uri; MateVFSResult result; uri = mate_vfs_uri_new (text_uri); if (uri == NULL) return MATE_VFS_ERROR_NOT_SUPPORTED; result = mate_vfs_get_file_info_uri(uri, info, options); mate_vfs_uri_unref (uri); return result; }
/** * mate_vfs_unlink: * @text_uri: uri of the file to be unlinked. * * Unlink @text_uri (i.e. delete the file). * * Return value: an integer representing the result of the operation. */ MateVFSResult mate_vfs_unlink (const gchar *text_uri) { MateVFSResult result; MateVFSURI *uri; g_return_val_if_fail (text_uri != NULL, MATE_VFS_ERROR_BAD_PARAMETERS); uri = mate_vfs_uri_new (text_uri); if (uri == NULL) return MATE_VFS_ERROR_INVALID_URI; result = mate_vfs_unlink_from_uri (uri); mate_vfs_uri_unref (uri); return result; }
/** * mate_vfs_make_directory: * @text_uri: uri of the directory to be created. * @perm: Unix-style permissions for the newly created directory * * Create @text_uri as a directory. * * Return value: an integer representing the result of the operation. */ MateVFSResult mate_vfs_make_directory (const gchar *text_uri, guint perm) { MateVFSResult result; MateVFSURI *uri; g_return_val_if_fail (text_uri != NULL, MATE_VFS_ERROR_BAD_PARAMETERS); uri = mate_vfs_uri_new (text_uri); if (uri == NULL) return MATE_VFS_ERROR_INVALID_URI; result = mate_vfs_make_directory_for_uri (uri, perm); mate_vfs_uri_unref (uri); return result; }
static void ih_event_callback (ik_event_t *event, ih_sub_t *sub) { gchar *fullpath, *info_uri_str; MateVFSURI *info_uri; MateVFSMonitorEventType gevent; gevent = ih_mask_to_EventType (event->mask); if (event->name) { fullpath = g_strdup_printf ("%s/%s", sub->dirname, event->name); } else { fullpath = g_strdup_printf ("%s/", sub->dirname); } info_uri_str = mate_vfs_get_uri_from_local_path (fullpath); info_uri = mate_vfs_uri_new (info_uri_str); g_free (info_uri_str); mate_vfs_monitor_callback ((MateVFSMethodHandle *)sub, info_uri, gevent); mate_vfs_uri_unref (info_uri); g_free(fullpath); }
static void call_monitors (gboolean add, char *filename) { MateVFSURI *info_uri, *base_uri; GList *l; if (local_monitors == NULL) return; base_uri = mate_vfs_uri_new ("dns-sd://local/"); info_uri = mate_vfs_uri_append_file_name (base_uri, filename); mate_vfs_uri_unref (base_uri); /* This queues an idle, so there are no reentrancy issues */ for (l = local_monitors; l != NULL; l = l->next) { mate_vfs_monitor_callback ((MateVFSMethodHandle *)l->data, info_uri, add?MATE_VFS_MONITOR_EVENT_CREATED:MATE_VFS_MONITOR_EVENT_DELETED); } mate_vfs_uri_unref (info_uri); }
/** * mate_vfs_open: * @handle: pointer to a pointer to a #MateVFSHandle object. * @text_uri: string representing the uri to open. * @open_mode: open mode. * * Open @text_uri according to mode @open_mode. On return, @handle will then * contain a pointer to a handle for the open file. * * Return value: an integer representing the result of the operation. */ MateVFSResult mate_vfs_open (MateVFSHandle **handle, const gchar *text_uri, MateVFSOpenMode open_mode) { MateVFSURI *uri; MateVFSResult result; g_return_val_if_fail (handle != NULL, MATE_VFS_ERROR_BAD_PARAMETERS); *handle = NULL; g_return_val_if_fail (text_uri != NULL, MATE_VFS_ERROR_BAD_PARAMETERS); uri = mate_vfs_uri_new (text_uri); if (uri == NULL) return MATE_VFS_ERROR_INVALID_URI; result = mate_vfs_open_uri (handle, uri, open_mode); mate_vfs_uri_unref (uri); return result; }
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; }