Changeset fa90c34 for util.c


Ignore:
Timestamp:
Dec 21, 2010, 5:54:43 PM (11 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
8510d5b
Parents:
9b9efa2b
git-author:
David Benjamin <davidben@mit.edu> (12/15/10 15:53:37)
git-committer:
David Benjamin <davidben@mit.edu> (12/21/10 17:54:43)
Message:
Fixup owl_util_recursive_resolve_link to handle relative symlinks

Relative paths in symlinks are resolve relative to the parent directory.
We need to correctly handle this case.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • util.c

    r9b9efa2b rfa90c34  
    391391gchar *owl_util_recursive_resolve_link(const char *filename)
    392392{
    393   gchar *last_filename = g_strdup(filename);
     393  gchar *last_path = g_strdup(filename);
    394394  GError *err = NULL;
    395   while (last_filename != NULL && g_file_test(last_filename, G_FILE_TEST_IS_SYMLINK)) {
    396     gchar *cur_filename = g_file_read_link(last_filename, &err);
    397     g_free(last_filename);
    398     last_filename = cur_filename;
    399   }
    400   if (last_filename == NULL) {
    401     owl_function_error("Cannot resolve symlinked file %s: %s",
    402                        filename, err->message);
    403     g_error_free(err);
    404   }
    405   return last_filename;
     395
     396  while (g_file_test(last_path, G_FILE_TEST_IS_SYMLINK)) {
     397    gchar *link_path = g_file_read_link(last_path, &err);
     398    if (link_path == NULL) {
     399      owl_function_error("Cannot resolve symlink %s: %s",
     400                         last_path, err->message);
     401      g_error_free(err);
     402      g_free(last_path);
     403      return NULL;
     404    }
     405
     406    /* Deal with obnoxious relative paths. If we really care, all this
     407     * is racy. Whatever. */
     408    if (!g_path_is_absolute(link_path)) {
     409      char *last_dir = g_path_get_dirname(last_path);
     410      char *tmp = g_build_path(G_DIR_SEPARATOR_S,
     411                               last_dir,
     412                               link_path,
     413                               NULL);
     414      g_free(last_dir);
     415      g_free(link_path);
     416      link_path = tmp;
     417    }
     418
     419    g_free(last_path);
     420    last_path = link_path;
     421  }
     422  return last_path;
    406423}
    407424
Note: See TracChangeset for help on using the changeset viewer.