Top |
This is a variety of functions for dealing with files and URIs, including locating installed files, finding user cache and config directories, and dealing with file naming restrictions for various filesystems.
const char *
rb_file (const char *filename
);
Searches for an installed file, returning the full path name if found, NULL otherwise.
const char *
rb_user_data_dir (void
);
This will create the rhythmbox user data directory, using the XDG Base Directory specification. If none of the XDG environment variables are set, this will be ~/.local/share/rhythmbox.
const char *
rb_user_cache_dir (void
);
This will create the rhythmbox user cache directory, using the XDG Base Directory specification. If none of the XDG environment variables are set, this will be ~/.cache/rhythmbox.
const char *
rb_music_dir (void
);
Returns the default directory for the user's music library. This will usually be the 'Music' directory under the home directory.
char *
rb_find_user_data_file (const char *name
);
Determines the full path to use for user-specific files, such as rhythmdb.xml,
within the user data directory (see rb_user_data_dir
).
char *
rb_find_user_cache_file (const char *name
);
Determines the full path to use for user-specific cached files within the user cache directory.
void
rb_file_helpers_init (void
);
Sets up file search paths for rb_file
. Must be called on startup.
void
rb_file_helpers_shutdown (void
);
Frees various data allocated by file helper functions. Should be called on shutdown.
char * rb_uri_resolve_symlink (const char *uri
,GError **error
);
Attempts to resolve symlinks in uri
and return a canonical URI for the file
it identifies.
gboolean
rb_uri_is_directory (const char *uri
);
Checks if uri
identifies a directory.
gboolean
rb_uri_exists (const char *uri
);
Checks if a URI identifies a resource that exists
gboolean
rb_uri_is_readable (const char *uri
);
Checks if the user can read the resource identified by uri
gboolean
rb_uri_is_writable (const char *uri
);
Checks if the user can write to the resource identified by uri
gboolean
rb_uri_is_local (const char *uri
);
Checks if uri
identifies a local resource. Currently this just
checks that it uses the 'file' URI scheme.
gboolean
rb_uri_is_hidden (const char *uri
);
Checks if uri
is hidden, according to the Unix filename convention.
If the filename component of uri
begins with a dot, the file is considered
hidden.
gboolean rb_uri_could_be_podcast (const char *uri
,gboolean *is_opml
);
Checks if uri
identifies a resource that is probably a podcast
(RSS or Atom feed). This does not perform any IO, it just guesses
based on the URI itself.
char *
rb_uri_make_hidden (const char *uri
);
Constructs a URI that is similar to uri
but which identifies
a hidden file. This can be used for temporary files that should not
be visible to the user while they are in use.
void rb_uri_handle_recursively (const char *uri
,GCancellable *cancel
,RBUriRecurseFunc func
,gpointer user_data
);
Calls func
for each file found under the directory identified by uri
.
If uri
identifies a file, calls func
for that instead.
uri |
URI to visit |
|
cancel |
an optional GCancellable to allow cancellation |
|
func |
Callback function. |
[scope call] |
user_data |
Data for callback function |
void rb_uri_handle_recursively_async (const char *uri
,GCancellable *cancel
,RBUriRecurseFunc func
,gpointer user_data
,GDestroyNotify data_destroy
);
Calls func
for each file found under the directory identified
by uri
, or if uri
identifies a file, calls it once
with that.
If non-NULL, destroy_data
will be called once all files have been
processed, or when the operation is cancelled.
uri |
the URI to visit |
|
cancel |
a GCancellable to allow cancellation |
|
func |
callback function |
|
user_data |
data to pass to callback |
|
data_destroy |
function to call to free |
gboolean rb_uri_mkstemp (const char *prefix
,char **uri_ret
,GOutputStream **stream
,GError **error
);
Creates a temporary file whose URI begins with prefix
, returning
the file URI and an output stream for writing to it.
char *
rb_canonicalise_uri (const char *uri
);
Converts uri
to canonical URI form, ensuring it doesn't contain
any redundant directory fragments or unnecessarily escaped characters.
All URIs passed to RhythmDB functions should be canonicalised.
char * rb_uri_append_path (const char *uri
,const char *path
);
Creates a new URI consisting of path
appended to uri
.
char * rb_uri_append_uri (const char *uri
,const char *fragment
);
Creates a new URI consisting of fragment
appended to uri
.
Generally isn't a good idea.
char *
rb_uri_get_dir_name (const char *uri
);
Returns the directory component of uri
, that is, everything up
to the start of the filename.
char *
rb_uri_get_short_path_name (const char *uri
);
Returns the filename component of uri
, that is, everything after the
final slash and before the start of the query string or fragment.
gboolean rb_check_dir_has_space (GFile *dir
,guint64 bytes_needed
);
Checks that the filesystem holding file
has at least bytes_needed
bytes available.
gboolean rb_check_dir_has_space_uri (const char *uri
,guint64 bytes_needed
);
Checks that the filesystem holding uri
has at least bytes_needed
bytes available.
char *
rb_uri_get_mount_point (const char *uri
);
Returns the mount point of the filesystem holding uri
.
If uri
is on a normal filesystem mount (such as /, /home,
/var, etc.) this will be NULL.
gboolean rb_uri_create_parent_dirs (const char *uri
,GError **error
);
Ensures that all parent directories of uri
exist so that
uri
itself can be created directly.
GFile *
rb_file_find_extant_parent (GFile *file
);
Walks up the filesystem hierarchy to find a GFile representing the nearest extant ancestor of the specified file, which may be the file itself if it exists.
char * rb_uri_get_filesystem_type (const char *uri
,char **mount_point
);
Returns a string describing the type of the filesystem containing uri
.
void
rb_sanitize_path_for_msdos_filesystem (char *path
);
Modifies path
such that it represents a legal path for MS DOS
filesystems. Note that it replaces forward slash characters,
so it's only appropriate for use with individual path segments
rather than entire paths.
char * rb_sanitize_uri_for_filesystem (const char *uri
,const char *filesystem
);
Removes characters from uri
that are not allowed by the filesystem
on which it would be stored, or a specific type of filesystem if specified.
At present, this only supports MS DOS filesystems.