diff options
| author | Tomas Bzatek <tbzatek@redhat.com> | 2024-10-25 11:41:45 +0200 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@redhat.com> | 2024-10-25 11:41:45 +0200 |
| commit | 921396db23f8281bec8372c680b89089de42703c (patch) | |
| tree | 3773c38f2b631ef3baf15859e98942bedf26c5e4 | |
| parent | 36d39e22091eb274a01eb6c1251bf107127c9c79 (diff) | |
| download | tuxcmd-modules-921396db23f8281bec8372c680b89089de42703c.tar.xz | |
gvfs: Implement manual file open-read-write-close
This makes cross-VFS copy work.
| -rw-r--r-- | gvfs/README | 14 | ||||
| -rw-r--r-- | gvfs/gvfs.c | 163 |
2 files changed, 120 insertions, 57 deletions
diff --git a/gvfs/README b/gvfs/README index 51a54c0..cfbd4a5 100644 --- a/gvfs/README +++ b/gvfs/README @@ -1,8 +1,6 @@ GVFS plugin for Tux Commander - Version: 0.1.10 - Release date: 2009-Oct-25 -Copyright (C) 2008-2009 Tomas Bzatek <tbzatek@users.sourceforge.net> +Copyright (C) 2008-2024 Tomas Bzatek <tbzatek@users.sourceforge.net> http://tuxcmd.sourceforge.net @@ -26,13 +24,3 @@ Feature highlights: To be implemented: * support for appending * authentication improvements (needs new VFS API) - - -The current VFS implementation in Tux Commander lacks some extended features -for both archiving and remote filesystems. This is one of the main goals for -the 0.6.x series. - -For successful compilation you will need working gcc compiler and glib2 -library installed with development files. - -Compilation has been tested with gcc compiler v4.4.2 diff --git a/gvfs/gvfs.c b/gvfs/gvfs.c index bc708f8..069d910 100644 --- a/gvfs/gvfs.c +++ b/gvfs/gvfs.c @@ -28,8 +28,8 @@ #include "logutils.h" -#define VERSION "0.2.3" -#define BUILD_DATE "2024-10-15" +#define VERSION "0.3" +#define BUILD_DATE "2024-10-25" #define DEFAULT_BLOCK_SIZE 0x10000 /* 64kB */ #define CONST_DEFAULT_QUERY_INFO_ATTRIBUTES G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK "," \ @@ -1146,44 +1146,6 @@ VFSBreakGetDirSize (struct TVFSGlobs *globs) /**************************************************************************************************************************************/ /**************************************************************************************************************************************/ -#if 0 -TVFSFileDes -VFSOpenFile (struct TVFSGlobs *globs, const char *APath, int Mode, int *Error) -{ - printf("(WW) VFSOpenFile: Not supported in GVFS plugin.\n"); - return NULL; -} - -TVFSResult -VFSCloseFile (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor) -{ - printf("(WW) VFSCloseFile: Not supported in GVFS plugin.\n"); - return cVFS_Not_Supported; -} - -guint64 -VFSFileSeek (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, guint64 AbsoluteOffset, int *Error) -{ - printf("(WW) VFSFileSeek: Not supported in GVFS plugin.\n"); - return 0; -} - -int -VFSReadFile (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, gpointer Buffer, int ABlockSize, int *Error) -{ - printf("(WW) VFSReadFile: Not supported in GVFS plugin.\n"); - return cVFS_Not_Supported; -} - -int -VFSWriteFile (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, gpointer Buffer, int BytesCount, int *Error) -{ - printf("(WW) VFSWriteFile: Not supported in GVFS plugin.\n"); - return cVFS_Not_Supported; -} -#endif - - void VFSSetBlockSize (struct TVFSGlobs *globs, guint32 Value) { @@ -1292,11 +1254,9 @@ vfs_copy_progress_callback (goffset current_num_bytes, goffset total_num_bytes, gpointer user_data) { - struct TVFSGlobs *globs; + struct TVFSGlobs *globs = user_data; - if (! user_data) - return; - globs = (struct TVFSGlobs *)user_data; + g_return_if_fail (user_data != NULL); if (globs->callback_progress) { if (! globs->callback_progress (current_num_bytes, NULL, globs->callback_data)) @@ -1408,6 +1368,121 @@ VFSCopyFromLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDs } +/**************************************************************************************************************************************/ +/**************************************************************************************************************************************/ + +TVFSFileDes +VFSOpenFile (struct TVFSGlobs *globs, const char *APath, int Mode, GError **error) +{ + GFile *file; + GFileInputStream *input_stream; + GFileOutputStream *output_stream; + + if (globs->file == NULL) { + log_error ("VFSOpenFile: globs->file == NULL!"); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "globs->file == NULL"); + return NULL; + } + + log_notice ("VFSOpenFile: Opening '%s'", APath); + file = g_file_resolve_relative_path (globs->file, APath); + if (file == NULL) { + log_error ("VFSOpenFile: g_file_resolve_relative_path() failed."); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Cannot resolve relative path for source file."); + return NULL; + } + + switch (Mode) { + case cVFS_OpenRead: + input_stream = g_file_read (file, NULL /* cancellable */, error); + g_object_unref (file); + return input_stream; + case cVFS_OpenWrite: + output_stream = g_file_create (file, G_FILE_CREATE_NONE, NULL /* cancellable */, error); + g_object_unref (file); + return output_stream; + case cVFS_OpenAppend: + output_stream = g_file_append_to (file, G_FILE_CREATE_NONE, NULL /* cancellable */, error); + g_object_unref (file); + return output_stream; + } + + log_error ("VFSOpenFile: Invalid file open mode %d", Mode); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Invalid file open mode %d", Mode); + g_object_unref (file); + return NULL; +} + +gboolean +VFSCloseFile (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, GError **error) +{ + if (G_IS_FILE_INPUT_STREAM (FileDescriptor)) { + return g_input_stream_close (G_INPUT_STREAM (FileDescriptor), + NULL /* cancellable */, + error); + } else + if (G_IS_FILE_OUTPUT_STREAM (FileDescriptor)) { + return g_output_stream_close (G_OUTPUT_STREAM (FileDescriptor), + NULL /* cancellable */, + error); + } + + log_error ("VFSCloseFile: Unknown file descriptor %p object type", FileDescriptor); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Unknown file descriptor %p object type", FileDescriptor); + return FALSE; +} + +gint64 +VFSReadFile (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, gpointer Buffer, guint64 ABlockSize, GError **error) +{ + if (G_IS_FILE_INPUT_STREAM (FileDescriptor)) { + return g_input_stream_read (G_INPUT_STREAM (FileDescriptor), + Buffer, + ABlockSize, + NULL /* cancellable */, + error); + } + + log_error ("VFSReadFile: Unknown file descriptor %p object type", FileDescriptor); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Unknown file descriptor %p object type", FileDescriptor); + return 0; +} + +gint64 +VFSWriteFile (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, gpointer Buffer, guint64 BytesCount, GError **error) +{ + if (G_IS_FILE_OUTPUT_STREAM (FileDescriptor)) { + return g_output_stream_write (G_OUTPUT_STREAM (FileDescriptor), + Buffer, + BytesCount, + NULL /* cancellable */, + error); + } + + log_error ("VFSWriteFile: Unknown file descriptor %p object type", FileDescriptor); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Unknown file descriptor %p object type", FileDescriptor); + return 0; +} + +guint64 +VFSFileSeek (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, guint64 AbsoluteOffset, GError **error) +{ + if (G_IS_FILE_INPUT_STREAM (FileDescriptor) || G_IS_FILE_OUTPUT_STREAM (FileDescriptor)) { + if (!g_seekable_seek (G_SEEKABLE (FileDescriptor), + AbsoluteOffset, + G_SEEK_SET, + NULL /* cancellable */, + error)) + return -1; + return g_seekable_tell (G_SEEKABLE (FileDescriptor)); + } + + log_error ("VFSFileSeek: Unknown file descriptor %p object type", FileDescriptor); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Unknown file descriptor %p object type", FileDescriptor); + return FALSE; +} + + /********** * TODO: |
