Skip to content
This repository has been archived by the owner on Jun 13, 2018. It is now read-only.

Problem: inconsistent path treatment leads to confusing behavior. #78

Merged
merged 1 commit into from
Mar 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 39 additions & 29 deletions src/ggfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,13 @@ build_directory_entries(char *pathname, char **error_msg)

if (errno)
{
*error_msg = xstrcpy(NULL, pathname, "/", dirst->file_name, ": ", strerror(errno), NULL);
*error_msg = xstrcpy(NULL, "'", clean_path(pathname),
dirst->file_name, "' ", strerror(errno), NULL);
}
else
{
*error_msg = xstrcpy(NULL, pathname, "/: is empty", NULL);
*error_msg = xstrcpy(NULL, "'", clean_path(pathname),
"' is empty", NULL);
}

close_dir (dirst);
Expand All @@ -457,15 +459,14 @@ build_directory_entries(char *pathname, char **error_msg)

/* The parent represents the original directory */
parent = memt_alloc (NULL, sizeof (DIRECTORY_ENTRY_ITEM));
curpath = strip_file_name (pathname);
parent-> path = xstrcpy (NULL, curpath, "/", NULL);
parent-> name = memt_strdup (NULL, strip_file_path (pathname));
parent-> dirst = NULL;
parent-> links = 0;
parent-> parent = NULL;
parent-> first_child = NULL;
parent-> sibling = NULL;
parent-> exists = TRUE;
parent-> path = xstrcpy (NULL, pathname, "/", NULL);
parent-> name = memt_strdup (NULL, pathname);
parent-> dirst = NULL;
parent-> links = 0;
parent-> parent = NULL;
parent-> first_child = NULL;
parent-> sibling = NULL;
parent-> exists = TRUE;

/* build a list of the directory children now so any
file access problems show up here and not during an iteration. */
Expand All @@ -480,14 +481,14 @@ build_directory_entries(char *pathname, char **error_msg)
#endif
{
directory = memt_alloc (NULL, sizeof (DIRECTORY_ENTRY_ITEM));
directory-> path = xstrcpy (NULL, dirst-> dir_name, "/", NULL);
directory-> name = memt_strdup (NULL, dirst-> file_name);
directory-> dirst = NULL;
directory-> links = 0;
directory-> parent = parent;
directory-> first_child = NULL;
directory-> sibling = NULL;
directory-> exists = TRUE;
directory-> path = xstrcpy (NULL, dirst-> dir_name, "/", NULL);
directory-> name = memt_strdup (NULL, dirst-> file_name);
directory-> dirst = NULL;
directory-> links = 0;
directory-> parent = parent;
directory-> first_child = NULL;
directory-> sibling = NULL;
directory-> exists = TRUE;

last_value = link_directory_entry (parent, last_value,
& directory_entry_class, directory);
Expand All @@ -507,7 +508,7 @@ build_directory_entries(char *pathname, char **error_msg)
file-> dirst = NULL;
file-> links = 0;
file-> parent = parent;
file-> sibling = NULL;
file-> sibling = NULL;
file-> handle = NULL;
file-> error_msg = NULL;

Expand Down Expand Up @@ -658,7 +659,7 @@ open_the_file (FILE_ENTRY_ITEM *file, char mode,
file-> path, "/", file-> name, NULL);

errno = 0;
file-> handle = file_open (filename, mode);
file-> handle = file_open (clean_path(filename), mode);
mem_free (filename);

return store_file_error (file, gsl_thread, error,
Expand Down Expand Up @@ -1264,9 +1265,10 @@ directory_open (int argc, RESULT_NODE **argv, void *item, RESULT_NODE *result, T
*context = item;
char
*curpath,
*pathname,
*fullpath,
*lastchar,
*error_msg;
*error_msg,
*relative;

DIRECTORY_ENTRY_ITEM
*directory;
Expand All @@ -1275,25 +1277,33 @@ directory_open (int argc, RESULT_NODE **argv, void *item, RESULT_NODE *result, T
rc;

ASSERT (context);

relative = path ? string_value (&path-> value) : ".";

// normalize relative path
#ifdef GATES_FILESYSTEM
strconvch (relative, PATHEND, '/');
#endif

// make absolute path, with trailing slash
curpath = get_curdir ();
pathname = locate_path (curpath,
path ? string_value (&path-> value) : ".");
fullpath = locate_path (curpath, relative);
mem_free (curpath);
lastchar = pathname + strlen (pathname) - 1;

// strip trailing slash
lastchar = fullpath + strlen (fullpath) - 1;
if (*lastchar == '/')
*lastchar = 0;
curpath = strip_file_name (pathname);

error_msg = NULL;
directory = build_directory_entries (pathname, &error_msg);
directory = build_directory_entries (fullpath, &error_msg);

if (directory)
{
assign_pointer (& result-> value, & directory_entry_class, directory);
}

mem_free (pathname);
mem_free (fullpath);

if (error_msg)
{
Expand Down
29 changes: 16 additions & 13 deletions src/sfldir.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ open_dir (

ASSERT (dir != NULL);
if (! dir)
return FALSE;
return FALSE;

memset (dir, 0, sizeof (DIRST));

Expand All @@ -105,18 +105,10 @@ open_dir (
if (dir_name == NULL || *dir_name == 0)
strcpy (dir_spec, DEFAULT_DIR);
else
strcpy (dir_spec, dir_name);
strcpy(dir_spec, clean_path(dir_name));

#if (defined (GATES_FILESYSTEM))
strconvch (dir_spec, '/', '\\');
#endif
/* Remove a trailing slash from the directory name */
/* Save the unmodified directory name for cleanup later */
dir_spec_end = dir_spec + strlen (dir_spec);
if (dir_spec_end [-1] == PATHEND)
{
dir_spec_end [-1] = '\0';
dir_spec_end--;
}

/* Open directory stream or find first directory entry */
#if (defined (__UNIX__) || defined (__VMS_XOPEN) || defined (__OS2__))
Expand Down Expand Up @@ -151,8 +143,15 @@ open_dir (
#if (defined (__MSDOS__) || defined (__OS2__))
*dir_spec_end = '\0'; /* Kill the \*.* again */
#endif

dir-> dir_name = dir_spec; /* Now owned by DIRST structure */

// normalize the path and filename
#ifdef GATES_FILESYSTEM
strconvch (dir-> dir_name, PATHEND, '/');
strconvch (dir-> file_name, PATHEND, '/');
#endif

#if (defined (__UNIX__) || defined (__VMS_XOPEN) || defined (__OS2__))
/* Under UNIX & VMS we still need to fetch the first file entry */
return (read_dir (dir));
Expand Down Expand Up @@ -210,6 +209,11 @@ populate_entry (DIRST *dir)
dir-> file_name = dir-> _dir_entry.ff_name;
#endif

// normalize the filename
#ifdef GATES_FILESYSTEM
strconvch (dir-> file_name, PATHEND, '/');
#endif

#if (defined (__UNIX__) || defined (GATES_FILESYSTEM))
/* If the filename is . or .., skip this entry and do the next. We */
/* use a little bit of a recursive call to make this code simple. */
Expand Down Expand Up @@ -1436,10 +1440,9 @@ remove_dir (
if (!file_is_directory (path))
return (-1);

copy_path = mem_strdup (path);
copy_path = mem_strdup (clean_path (path));
if (copy_path)
{
strconvch (copy_path, '/', '\\');
# if (defined (WIN32))
if (RemoveDirectoryA (copy_path))
rc = 0;
Expand Down
22 changes: 10 additions & 12 deletions src/sflfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ system_devicename (const char *supplied_filename)
CloseHandle(fh);
}
else
is_devicefile = FALSE; /* Doesn't exist */
is_devicefile = FALSE; /* Doesn't exist */

return (is_devicefile);
#else
Expand Down Expand Up @@ -1680,11 +1680,11 @@ char
/* ---------------------------------------------------------------------[<]-
Function: strip_file_name

Synopsis: Returns the path for a fully-qualified filename. The path is
cleaned-up and resolved. The returned string is held in a static area
that should be copied directly after calling this function. The returned
path does not end in '/' unless that is the entire path. If the supplied
name contains no path, the returned path is ".".
Synopsis: Returns the path for a fully-qualified filename. The returned
string is held in a static area that should be copied directly after
calling this function. The returned path does not end in '/' unless
that is the entire path. If the supplied name contains no path, the
returned path is ".".
---------------------------------------------------------------------[>]-*/

char
Expand All @@ -1697,18 +1697,16 @@ char
ASSERT (strlen (name) <= LINE_MAX);

strcpy (work_name, name);
path_end = strrchr (work_name, PATHEND);
path_end = strrchr (work_name, PATHEND); /* Find end of path, if any */
#if (defined (GATES_FILESYSTEM))
if (path_end == NULL)
path_end = strrchr (work_name, '/');
#endif
if (path_end == NULL)
return (".");
else
{
path_end [1] = '\0';
return (clean_path (work_name));
}

path_end [1] = '\0';
return work_name;
}


Expand Down