Re: File copying
On Mon, 7 Feb 2011 07:58:57 + John Emmas john...@tiscali.co.uk wrote: On 6 Feb 2011, at 19:05, Nader Morshed wrote: Thanks Nader. Is this the document you mean:- http://library.gnome.org/devel//gio/2.26/GFileInfo.html Yep, or in particular: http://library.gnome.org/devel/gio/2.26/GFileInfo.html#GFileInfo.description g_file_query_info (pDestObject, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, false, error); The API for g_file_query_info states that the 4th parameter should be a GCancellable object or NULL, though in this case no error occurs because false == 0 == NULL. http://library.gnome.org/devel/gio/2.26/GFile.html#g-file-query-info void SetHiddenAttribute (GFile* pFile, GFileInfo* pInfo, GError** ppError) { GError* error = NULL; g_file_info_set_is_hidden (pinfo, true); g_file_set_attributes_from_info (pFile, pInfo, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, error); if (error) g_propagate_error (ppError, error); } I believe you can pass ppError directly to g_file_set_attributes_from_info() in this case, as you just copy error over anyways, but you might want to double-check that, it otherwise looks fine. However, the call to g_file_set_attributes_from_info() fails with this error:- error code 15 : message=0x02894d80 Setting attribute standard::is-hidden not supported It seems that would be due to a rather crummy implementation of GLocalFile which only handles getting the standard::is-hidden attribute, not setting it: http://git.gnome.org/browse/glib/tree/gio/glocalfileinfo.c#n2200 I might advise bugging your nearest glib developer to fix this :) -- Nader Morshed morshed.na...@gmail.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: File copying
On 5 Feb 2011, at 19:18, Kevin DeKorte wrote: Something like this GFile *file; GFileOutputStream *output; GDataOutputStream *data; file = g_file_new_for_uri(uri); output = g_file_replace(file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL); data = g_data_output_stream_new((GOutputStream *) output); if (data != NULL) { g_data_output_stream_put_string(data, #EXTM3U\n, NULL, NULL); g_output_stream_close((GOutputStream *) data, NULL, NULL); } Kevin Thanks David and Kevin for the suggestions. That worked fine once I realised that I could cast from GFileOutputStream* to GOutputStream*. I used the built-in macros G_INPUT_STREAM(x) and G_OUTPUT_STREAM(x) but I think they essentially do the same thing. The only problem I'm having now is when I later come to copy the file attributes and last modification time. Take a look at this code and tell me if i'm doing something wrong void CopyModificationtimeAndAttributes (GFileInfo* pSrcModule, GFileInfo* pDestModule) { GTimeVal tvModificationTime; gboolean bIsHidden; g_return_if_fail (G_IS_FILE_INFO (pSrcModule)); g_return_if_fail (G_IS_FILE_INFO (pDestModule)); g_file_info_get_modification_time (pSrcModule, tvModificationTime); g_file_info_set_modification_time (pDestModule, tvModificationTime); /* Note this line for testing */ g_file_info_get_modification_time (pDestModule, tvModificationTime); /* bIsHidden = g_file_info_get_is_hidden (pSrcModule); */ /* Note this line for testing */ bIsHidden = true; g_file_info_set_is_hidden (pDestModule, bIsHidden); } You can see that I specifically set the copied file to be hidden (I'm running this under Windows 7 BTW on a FAT32 partition, so no security permissions to worry about). Note also, that after setting the modification time I specifically check (in my debugger) that the destination file has the correct time, which it does. However, if I navigate to the destination file in Windows Explorer and inspect its properties I see that the file wasn't in fact hidden, nor does it have the modification time I specified. Have I missed out a step? For example although you can't see it in the above code I did flush the file contents and closed it (after copying the data) but I only unref'd the GFileInfo pointers. I didn't carry out any similar closing or flushing operations for the new time and attributes. Should I have done something to actually write the changed details to disk? John ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: File copying
You need to call g_file_set_attributes_from_info() to apply your changes to the file info (See: The Description section in the GFileInfo gtk-docs) I might also suggest filtering results on your query of g_file_query_info and just using a loop to copy over all the attributes listed by g_file_info_list_attributes(), it would allow you to add in more fields more easily, rather than having to write new lines of code for each new field that you decide to care about. On Sun, 6 Feb 2011 17:04:26 + John Emmas john...@tiscali.co.uk wrote: On 5 Feb 2011, at 19:18, Kevin DeKorte wrote: Something like this GFile *file; GFileOutputStream *output; GDataOutputStream *data; file = g_file_new_for_uri(uri); output = g_file_replace(file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL); data = g_data_output_stream_new((GOutputStream *) output); if (data != NULL) { g_data_output_stream_put_string(data, #EXTM3U\n, NULL, NULL); g_output_stream_close((GOutputStream *) data, NULL, NULL); } Kevin Thanks David and Kevin for the suggestions. That worked fine once I realised that I could cast from GFileOutputStream* to GOutputStream*. I used the built-in macros G_INPUT_STREAM(x) and G_OUTPUT_STREAM(x) but I think they essentially do the same thing. The only problem I'm having now is when I later come to copy the file attributes and last modification time. Take a look at this code and tell me if i'm doing something wrong void CopyModificationtimeAndAttributes (GFileInfo* pSrcModule, GFileInfo* pDestModule) { GTimeVal tvModificationTime; gboolean bIsHidden; g_return_if_fail (G_IS_FILE_INFO (pSrcModule)); g_return_if_fail (G_IS_FILE_INFO (pDestModule)); g_file_info_get_modification_time (pSrcModule, tvModificationTime); g_file_info_set_modification_time (pDestModule, tvModificationTime); /* Note this line for testing */ g_file_info_get_modification_time (pDestModule, tvModificationTime); /* bIsHidden = g_file_info_get_is_hidden (pSrcModule); */ /* Note this line for testing */ bIsHidden = true; g_file_info_set_is_hidden (pDestModule, bIsHidden); } You can see that I specifically set the copied file to be hidden (I'm running this under Windows 7 BTW on a FAT32 partition, so no security permissions to worry about). Note also, that after setting the modification time I specifically check (in my debugger) that the destination file has the correct time, which it does. However, if I navigate to the destination file in Windows Explorer and inspect its properties I see that the file wasn't in fact hidden, nor does it have the modification time I specified. Have I missed out a step? For example although you can't see it in the above code I did flush the file contents and closed it (after copying the data) but I only unref'd the GFileInfo pointers. I didn't carry out any similar closing or flushing operations for the new time and attributes. Should I have done something to actually write the changed details to disk? John ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list -- Nader Morshed morshed.na...@gmail.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: File copying
On 6 Feb 2011, at 19:05, Nader Morshed wrote: You need to call g_file_set_attributes_from_info() to apply your changes to the file info (See: The Description section in the GFileInfo gtk-docs) I might also suggest filtering results on your query of g_file_query_info Thanks Nader. Is this the document you mean:- http://library.gnome.org/devel//gio/2.26/GFileInfo.html If so, there's something I'm still not understanding. I've cut my example down to some code that should set the 'hidden' attribute on a pre-existing file. I obtain a GFile* and GFileInfo* like this:- GFile* pDestObject = g_file_new_for_path (path_to_my_existing_file); GFileInfo* pDestObjectInfo = g_file_query_info (pDestObject, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, false, error); The above calls appear to succeed. I then pass the pointers to this function:- void SetHiddenAttribute (GFile* pFile, GFileInfo* pInfo, GError** ppError) { GError* error = NULL; g_file_info_set_is_hidden (pinfo, true); g_file_set_attributes_from_info (pFile, pInfo, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, error); if (error) g_propagate_error (ppError, error); } However, the call to g_file_set_attributes_from_info() fails with this error:- error code 15 : message=0x02894d80 Setting attribute standard::is-hidden not supported I'd be happy to look at an example if you know where I can find one. Otherwise, can you see where I'm going wrong? Thanks, John ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: File copying
On 4 Feb 2011, at 22:57, Nader Morshed wrote: you might want to take a look at GIO's GFileInfo API. It has a large array of attributes to get/set, depending on the GIOModule being used. Thanks for the tip. I've been experimenting with the GFileInfo API today but inadvertently, it's led me to something of a dead end. Remember that apart from wanting to preserve certain file attributes, my main aim was to move some files into a new folder (i.e. creating a new file or overwriting an older version, then deleting the original). g_file_replace() seems to provide a handy interface for this type of operation, since it'll allow me to overwrite a pre-existing file in the destination folder or create a new one if the destination file didn't already exist. g_file_replace() returns a GFileOutputStream* which (supposedly) I can use for writing new contents to the file. However, I've been unable to find any examples of writing to a file using a GFileOutputStream*. In fact, I can't find any read, write, flush. or, close functions that take a GFileOutputStream* as their input. What am I missing here? Am I supposed to turn my GFileOutputStream* into some other kind of stream (for example a GOutputStream*)? I've found plenty of functions for using GOutputStream but am struggling with GFileOutputStream. Thanks. John ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: File copying
On Sat, Feb 05, 2011 at 06:29:20PM +, John Emmas wrote: g_file_replace() returns a GFileOutputStream* which (supposedly) I can use for writing new contents to the file. However, I've been unable to find any examples of writing to a file using a GFileOutputStream*. In fact, I can't find any read, write, flush. or, close functions that take a GFileOutputStream* as their input. What am I missing here? Am I supposed to turn my GFileOutputStream* into some other kind of stream (for example a GOutputStream*)? I've found plenty of functions for using GOutputStream but am struggling with GFileOutputStream. GFileOutputStream is GOutputStream as can be seen in the class hierarchy: http://library.gnome.org/devel/gio/stable/GFileOutputStream.html#GFileOutputStream.object-hierarchy So you only have to use the standard typecasting macros. Yeti ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: File copying
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 02/05/2011 11:29 AM, John Emmas wrote: On 4 Feb 2011, at 22:57, Nader Morshed wrote: you might want to take a look at GIO's GFileInfo API. It has a large array of attributes to get/set, depending on the GIOModule being used. Thanks for the tip. I've been experimenting with the GFileInfo API today but inadvertently, it's led me to something of a dead end. Remember that apart from wanting to preserve certain file attributes, my main aim was to move some files into a new folder (i.e. creating a new file or overwriting an older version, then deleting the original). g_file_replace() seems to provide a handy interface for this type of operation, since it'll allow me to overwrite a pre-existing file in the destination folder or create a new one if the destination file didn't already exist. g_file_replace() returns a GFileOutputStream* which (supposedly) I can use for writing new contents to the file. However, I've been unable to find any examples of writing to a file using a GFileOutputStream*. In fact, I can't find any read, write, flush. or, close functions that take a GFileOutputStream* as their input. What am I missing here? Am I supposed to turn my GFileOutputStream* into some other kind of stream (for example a GOutputStream*)? I've found plenty of functions for using GOutputStream but am struggling with GFileOutputStream. Thanks. John John, Something like this GFile *file; GFileOutputStream *output; GDataOutputStream *data; file = g_file_new_for_uri(uri); output = g_file_replace(file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL); data = g_data_output_stream_new((GOutputStream *) output); if (data != NULL) { g_data_output_stream_put_string(data, #EXTM3U\n, NULL, NULL); g_output_stream_close((GOutputStream *) data, NULL, NULL); } Kevin - -- Get my public GnuPG key from http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0x7D0BD5D1 -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iEYEARECAAYFAk1NooYACgkQ6w2kMH0L1dEcgACfaD3sGP2pKKZCRl+gC7T8Gj38 YewAmgL5Pd5UnPgarGav7Ynd7fA8pmWw =dKXE -END PGP SIGNATURE- ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: File copying
Glib has a few various functions for that, like g_chmod, g_stat, etc, but you might want to take a look at GIO's GFileInfo API. It has a large array of attributes to get/set, depending on the GIOModule being used. On Fri, 4 Feb 2011 22:51:36 + John Emmas john...@tiscali.co.uk wrote: Does glib have any functions for setting a file's attributes / creation date / last modification date etc? I need to move some files (programmatically) to a new directory whilst preserving their dates and other attributes. John ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list -- Nader Morshed morshed.na...@gmail.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list