Commit Graph

175 Commits

Author SHA1 Message Date
Colin Walters
f398bec5bc Add g_close(), use it
There are two benefits to this:

1) We can centralize any operating system specific knowledge of
   close-vs-EINTR handling.  For example, while on Linux we should never
   retry, if someone cared enough later about HP-UX, they could come by
   and change this one spot.
2) For places that do care about the return value and want to provide
   the caller with a GError, this function makes it convenient to do so.

Note that gspawn.c had an incorrect EINTR loop-retry around close().

https://bugzilla.gnome.org/show_bug.cgi?id=682819
2013-01-29 09:46:04 -05:00
Colin Walters
166766a89f GFile: Clean up file_copy_fallback to fix SEGV with btrfs
Ok, this function was just an awful mess before.  Now the problem
domain is not trivial, and I won't claim this new code is *beautiful*,
but it should fix the bug at hand, and be somewhat less prone to
failure for the next person who tries to modify it.  There's only one
unref call for each object now.

https://bugzilla.gnome.org/show_bug.cgi?id=692408
2013-01-27 11:04:48 -05:00
Colin Walters
48fd507012 gfile: Ensure we create internal pipe with FD_CLOEXEC
That way the descriptors aren't leaked to child processes.

https://bugzilla.gnome.org/show_bug.cgi?id=692544
2013-01-25 13:45:07 -05:00
Cosimo Cecchi
e908b50371 gfile: don't report completion twice on g_file_load_contents error
When an error occurs while reading the file input stream in
g_file_load_contents (e.g. because the operation was cancelled), the
code is correctly calling g_task_return_error(), but in the callback
from the close operation, g_task_return_boolean() will be called again.

Code that cleans up its state in the async callback will then be called
twice, leading to invalid memory access.

https://bugzilla.gnome.org/show_bug.cgi?id=692202
2013-01-21 10:36:42 -05:00
Nirbheek Chauhan
5eba978497 GFile: Add Btrfs clone ioctl support
The attached patch adds support for the btrfs "clone" ioctl which
makes Copy-on-Write reflinks, resulting in cheap O(1) copies when
source/destination are on the same filesystem. The ioctl itself is
quite straightforward, and GNU coreutils has had support since 7.5
(--reflink=auto --sparse=auto).

The ioctl only operates on regular files and symlinks, and always
follows symlinks; checks have been added accordingly.

This patch would be very useful for everyone who uses btrfs
filesystems (Meego folks for instance). On systems that don't have
btrfs, or if the the source is not on a btrfs filesystem, the ioctl
returns EINVAL, and the fallback code is triggered. Hence this will
cause no problems for non-btrfs users.

https://bugzilla.gnome.org/show_bug.cgi?id=626497
2013-01-05 14:21:25 -05:00
Ryan Lortie
707bc4a40f gio + inotify support for hard links
Add a new GFileMonitorFlag: G_FILE_MONITOR_WATCH_HARD_LINKS.  When set,
changes made to the file via another hard link will be detected.

Implement the new flag for the inotify backend.

https://bugzilla.gnome.org/show_bug.cgi?id=532815
2012-12-19 08:19:18 -05:00
Dan Winship
ed5accf16c gio: port file/vfs-related classes from GSimpleAsyncResult to GTask
https://bugzilla.gnome.org/show_bug.cgi?id=661767
2012-12-18 09:07:24 -05:00
Tomas Bzatek
cc3171f680 docs: Fix return value of g_file_set_attributes_from_info()
GIO API usually returns FALSE and sets GError when something went wrong
and it was also the case of this method, just being badly documented.
2012-12-14 16:54:09 +01:00
Matthias Clasen
a5f57bad20 g_file_enumerate_children: Fix reference to wrong error code
This function does in fact return G_IO_ERROR_NOT_DIRETORY, and
not G_FILE_ERROR_NOTDIR.
2012-11-30 09:05:41 -05:00
Ryan Lortie
3baf256a2c gio: New API for GFile from remote commandline arg
Add a pair of new APIs: one to GFile to create a new file from a
commandline arg relative to a given cwd and one to
GApplicationCommandLine to create a GFile from an arg, relative to the
cwd of the invoking commandline.

https://bugzilla.gnome.org/show_bug.cgi?id=689037
2012-11-27 10:10:37 -05:00
Dan Winship
55e7ca6e1b gio: deprecate gioscheduler, soft deprecate GSimpleAsyncResult
Reimplement gioscheduler in terms of GTask, and deprecate the original
gioscheduler methods. Update docs to point people to GTask rather than
gioscheduler and GSimpleAsyncResult, but don't actually formally
deprecate GSimpleAsyncResult yet.

https://bugzilla.gnome.org/show_bug.cgi?id=661767
2012-10-10 10:29:36 -04:00
Matthias Clasen
344066e0c1 Fix gio docs 2012-09-23 02:18:56 -04:00
Dan Winship
039ecf2bc6 g_file_copy: plug a leak
The fallback copy code was leaking the GFileInfo if it didn't have
G_FILE_ATTRIBUTE_STANDARD_TYPE.

https://bugzilla.gnome.org/show_bug.cgi?id=682560
2012-09-03 08:40:14 -04:00
Matthias Clasen
a552989410 GFile: Cosmetic doc changes 2012-08-28 00:08:05 -04:00
Owen W. Taylor
f899358156 g_file_make_directory_with_parents: clean up logic
Simplify logic by only looking at whether we have a GError and
not also using return codes.

https://bugzilla.gnome.org/show_bug.cgi?id=680823
2012-08-16 18:08:06 -04:00
Owen W. Taylor
5291190f46 g_file_make_directory_with_parents(): fix a corner case
If g_file_get_parent() unexpectedly failed, we could return
FALSE but with no error.

https://bugzilla.gnome.org/show_bug.cgi?id=680823
2012-08-16 18:08:05 -04:00
Owen W. Taylor
732470a359 g_file_make_directory_with_parents: refix error propagation
The patch from b0bce4ad triggered segfaults - see:

 http://redmine.yorba.org/issues/5656

We were clearing the error before dereferencing it in the next
go-around of the while loop - this wasn't necessary.

https://bugzilla.gnome.org/show_bug.cgi?id=680823
2012-08-16 18:08:03 -04:00
Owen W. Taylor
b0bce4ad41 g_file_make_directory_with_parents: Fix error propagation
When creating a directory fails for some reason other than
the parent not existing, don't clear the error before we try
to propagate it.

To reproduce, run 'ostadmin init' on /ostree or otherwise try to
run the function on a directory with a parent directory where the
current user is not allowed to write.

https://bugzilla.gnome.org/show_bug.cgi?id=680823
2012-07-30 18:29:26 +02:00
Colin Walters
d7829ced53 GFile: Note semantics of g_file_delete()
Particularly for someone programming on Unix, this helps them
understand that we will unlink symbolic links, and not follow them.
2012-07-30 05:11:08 -04:00
Colin Walters
14a1c20177 GFile: Add g_file_delete_async()
This looks like it was stubbed out but not implemented; the vtable
entry dates to commit 3781343738 which
is just alex's initial merge of gio into glib.

I was working on some code that wants an asynchronous rm -rf
equivalent, and so yeah, this is desirable.

https://bugzilla.gnome.org/show_bug.cgi?id=680760
2012-07-30 05:01:06 -04:00
Dan Winship
f8532a13e2 gio: Add g_async_result_legacy_propagate_error()
Finish deprecating the "handle GSimpleAsyncResult errors in the
wrapper function" idiom (and protect against future GSimpleAsyncResult
deprecation warnings) by adding a "legacy" GAsyncResult method
to do it in those classes/methods where it had been traditionally
done.

(This applies only to wrapper methods; in cases where an _async
vmethod explicitly uses GSimpleAsyncResult, its corresponding _finish
vmethod still uses g_simple_async_result_propagate_error.)

https://bugzilla.gnome.org/show_bug.cgi?id=667375
https://bugzilla.gnome.org/show_bug.cgi?id=661767
2012-07-10 10:49:14 -04:00
Dan Winship
538b2f106d gio: handle GSimpleAsyncResult errors in _finish vmethods
Originally, the standard idiom with GSimpleAsyncResult was to handle
all errors in the _finish wrapper function, so that vmethods only had
to deal with successful results. But this means that chaining up to a
parent _finish vmethod won't work correctly. Fix this by also checking
for errors in all the relevant vmethods. (We have to redundantly check
in both the vmethod and the wrapper to preserve compatibility.)

https://bugzilla.gnome.org/show_bug.cgi?id=667375
https://bugzilla.gnome.org/show_bug.cgi?id=661767
2012-07-10 10:47:55 -04:00
Dan Winship
a98d26c9bb GFile: remove some unnecessary code
The "mainloop_barrier" in copy_async_thread() is unnecessary, since
the g_simple_async_result_complete_in_idle() will be queued after all
of the g_io_scheduler_job_send_to_mainloop_async()s, and sources with
the same priority will run in the order in which they were queued.

https://bugzilla.gnome.org/show_bug.cgi?id=661767
2012-07-10 10:47:49 -04:00
Debarshi Ray
6e32f0a601 gio: The tmpl parameter to g_file_new_tmp can be NULL
Fixes: https://bugzilla.gnome.org/676208
2012-05-21 17:54:25 +02:00
Paolo Borelli
2a4235d0f3 gfile: add g_return_if_fail to g_file_make_directory_with_parents() 2012-05-15 17:39:38 +02:00
Colin Walters
5a57144d57 gfile: Plug memory leak in g_file_make_directory_with_parents()
The logic here is pretty twisted, but basically we were leaking a ref
for each non-existent parent.  The clearest way to fix this was to
move to more explicit refcounting logic; when a variable is pointing
to an object, it holds a ref.

https://bugzilla.gnome.org/show_bug.cgi?id=675446
2012-05-15 11:07:33 -04:00
Dieter Verfaillie
8e740f726f Fix malformed GTK-Doc comment blocks: add missing colons.
Found these thanks to improved gobject-introspection GTK-Doc
comment block/annotation parser from:
https://bugzilla.gnome.org/show_bug.cgi?id=672254

https://bugzilla.gnome.org/show_bug.cgi?id=673385
2012-04-05 10:23:39 -03:00
Robert Ancell
4143842eb4 Add missing allow-none annotations for function parameters.
Found using:
find . -name '*.c' | xargs grep 'or %NULL' | grep ' \* @' | grep -v '@error' | grep -v allow-none
2012-03-31 20:34:28 +11:00
Thomas Hindoe Paaboel Andersen
4ce98d3b59 docs: g_file_new_tmp: template was renamed to tmpl 2012-02-26 07:35:12 -05:00
Evan Nemerson
c3d6595f5a GIO: add lots of annotations for Vala bindings
https://bugzilla.gnome.org/show_bug.cgi?id=667447
2012-01-11 15:50:08 -05:00
Matthias Clasen
f0eb58075a Add a since tag 2011-12-10 21:55:11 -05:00
Colin Walters
4eeac41d7d gfile: Don't use C++ keyword "template" as variable name
This breaks autotestkeyword.cc from gtk+.
2011-12-09 11:13:23 -05:00
Thomas Hindoe Paaboel Andersen
721667399a GFile: add g_file_new_temp
A convenience function that creates a temporary file and returns
a GFile and GFileIOStream for it.

The file is created using g_file_open_tmp.

https://bugzilla.gnome.org/show_bug.cgi?id=657085
2011-12-09 08:58:05 -05:00
Michael Vogt
0627759331 Add missing annotation to g_file_set_attribute()
g_file_set_attribute() also permits a NULL value for value_p, and requires it
to be NULL to unset it. Also fix the wrong variable name in the documentation.

Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
2011-11-29 12:01:25 +01:00
Matthias Clasen
0878f5ba43 GFile: Add some introspection annotations
progress_callback in g_file_copy and g_file_copy_async may be NULL.
Annotations should reflect that. Pointed out by Carlo Teubner.

https://bugzilla.gnome.org/show_bug.cgi?id=664415
2011-11-20 15:12:05 -05:00
Torsten Schönfeld
70eff50f21 Add two annotations to gio
https://bugzilla.gnome.org/show_bug.cgi?id=656679
2011-10-15 18:02:32 -04:00
Bastien Nocera
82fae72ae9 [gio] Improve doc for g_file_make_directory_with_parents()
g_file_make_directory_with_parents() will fail for already
existing directories, unlike g_mkdir_with_parents(), so mention
this clearly in the docs.

https://bugzilla.gnome.org/show_bug.cgi?id=660791
2011-10-04 17:10:39 +01:00
Javier Jardón
6d05f684eb gfile: Be clear about freeing GFile objects 2011-09-29 20:04:28 +01:00
Matthias Clasen
1b28408b8b Spelling fixes
Spelling fixes in comments and docs, provided by
Kjartan Maraas in bug 657336.
2011-08-29 14:49:32 -04:00
Tomas Bzatek
fb45baaf8c Docs: Correct the namespace for g_file_query_filesystem_info() 2011-07-26 17:32:53 +02:00
Holger Berndt
d1e5161ab0 Document how to unset attributes
Unsetting won't work on all attributes. Currently, only
metadata attributes are supported.

https://bugzilla.gnome.org/show_bug.cgi?id=620423
2011-07-19 22:52:56 +02:00
Dan Winship
e56498ee0b Fix usage of _GNU_SOURCE
_GNU_SOURCE must be defined before including any other (system)
header, so defining it in glib-unix.h (and hoping no one has included
anything else before that) is wrong. And the "#define _USE_GNU"
workaround for this problem in gnetworkingprivate.h is even wronger
(and still prone to failure anyway due to single-include guards).

Fix this by defining _GNU_SOURCE in config.h when building against
glibc. In theory this is bad because new releases of glibc may include
symbols that conflict with glib symbols, which could then cause
compile failures. However, most people only see new releases of glibc
when they upgrade their distro, at which point they also generally get
new releases of gcc, which have new warnings/errors to clean up
anyway.

https://bugzilla.gnome.org/show_bug.cgi?id=649201
2011-05-03 07:07:41 -04:00
Jonathan Matthew
95e7aa0e07 introspection: add annotations for g_file_load_contents and friends
https://bugzilla.gnome.org/show_bug.cgi?id=645789
2011-03-29 19:40:26 +10:00
Pavel Holejsovsky
89b558077f [gi] Add annotations for GFile, G[File]{Input|Output|IO}Stream.
Also make parameter names in virtual function declarations consistent
to silent g-ir-scanner.
2010-12-17 16:29:05 +01:00
Colin Walters
260d005616 introspection: Add annotations for g_file_copy, g_file_move 2010-11-17 20:07:39 -05:00
Christian Persch
9e0c07870a Use g_simple_async_result_{new_,}take_error
Bug #633685.
2010-11-03 14:25:35 +01:00
Johan Dahlin
30132c44c1 Add a lot of missing annotations 2010-09-24 18:24:41 -03:00
Johan Dahlin
835f9cb310 [introspection] Move over annotations
Move all the annotations over from gobject-introspection.

They will not be used directly by the introspection scanner for now,
instead they will be extracted by a script and updated manually
until introspection is properly integrated into the glib build
2010-09-24 15:52:38 -03:00
Benjamin Otte
1254104cea docs: Clarify string encoding for GFile constructors
The encoding was deduced from looking at the source code, feel free to
fix if it's wrong (the docs _and_ the source code).
2010-09-11 00:13:36 +02:00
Matthias Clasen
c24a29e13b Adapt to recent MLS changes
g_file_query_info returns non-NULL more often now.
2010-07-09 07:24:08 -04:00