Skip to content

Commit

Permalink
bugfix: paths.c: slashes were doubled while processing root directory…
Browse files Browse the repository at this point in the history
… components

- A doubled slash appeared sometimes (at least when mkdir -p was
  processing relative paths in the root directory)
- C/Lua interface version was incremented to 70.
  • Loading branch information
lauri-aarnio committed Jan 26, 2010
1 parent d888d2a commit 101799b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
4 changes: 3 additions & 1 deletion include/sb2.h
Expand Up @@ -76,10 +76,12 @@ struct lua_instance {
* - added a wrapper for popen(). Added a new function to argvenvp.lua.
* * Differences between "69" and "68"
* - minor changes to the popen() implementation.
* * Differences between "70" and "69"
* - bug fixes in luaif/paths.c
*
* NOTE: the corresponding identifier for Lua is in lua_scripts/main.lua
*/
#define SB2_LUA_C_INTERFACE_VERSION "69"
#define SB2_LUA_C_INTERFACE_VERSION "70"

extern struct lua_instance *get_lua(void);
extern void release_lua(struct lua_instance *ptr);
Expand Down
2 changes: 1 addition & 1 deletion lua_scripts/main.lua
Expand Up @@ -14,7 +14,7 @@ debug_messages_enabled = sb.debug_messages_enabled()
--
-- NOTE: the corresponding identifier for C is in include/sb2.h,
-- see that file for description about differences
sb2_lua_c_interface_version = "69"
sb2_lua_c_interface_version = "70"

function do_file(filename)
if (debug_messages_enabled) then
Expand Down
48 changes: 32 additions & 16 deletions luaif/paths.c
Expand Up @@ -185,18 +185,27 @@ static char *path_entries_to_string_until(
/* add path components to the buffer */
work = p_entry;
if (flags & PATH_FLAGS_ABSOLUTE) {
strcat(buf, "/");
strcpy(buf, "/");
}
while (work) {
strcat(buf, work->pe_path_component);
int component_is_empty;
if (*work->pe_path_component) {
strcat(buf, work->pe_path_component);
component_is_empty = 0;
} else {
component_is_empty = 1;
}
if (work == last_path_entry_to_include) break;
work = work->pe_next;
if (work) {
if (work && (component_is_empty==0)) {
strcat(buf, "/");
}
}
if (flags & PATH_FLAGS_HAS_TRAILING_SLASH) {
strcat(buf, "/");
char *cp = buf;
/* point to last char in buf */
while (*cp && cp[1]) cp++;
if (*cp != '/') strcat(buf, "/");
}

return(buf);
Expand Down Expand Up @@ -1460,20 +1469,27 @@ static int relative_virtual_path_to_abs_path(
virtual_reversed_cwd);
} else {
/* "cache miss" */
SB_LOG(SB_LOGLEVEL_DEBUG,
"sbox_map_path_internal: reversing cwd:");
virtual_reversed_cwd = call_lua_function_sbox_reverse_path(
ctx, host_cwd);
if (virtual_reversed_cwd == NULL) {
/*
* In case reverse path couldn't be resolved
* we fallback into host_cwd. This is the
* way it used to work before.
*/
if ( (host_cwd[1]=='\0') && (*host_cwd=='/') ) {
SB_LOG(SB_LOGLEVEL_DEBUG,
"sbox_map_path_internal: no need to reverse, '/' is always '/'");
/* reversed "/" is always "/" */
virtual_reversed_cwd = strdup(host_cwd);
} else {
SB_LOG(SB_LOGLEVEL_DEBUG,
"unable to reverse, using reversed_cwd=%s",
virtual_reversed_cwd);
"sbox_map_path_internal: reversing cwd(%s)", host_cwd);
virtual_reversed_cwd = call_lua_function_sbox_reverse_path(
ctx, host_cwd);
if (virtual_reversed_cwd == NULL) {
/*
* In case reverse path couldn't be resolved
* we fallback into host_cwd. This is the
* way it used to work before.
*/
virtual_reversed_cwd = strdup(host_cwd);
SB_LOG(SB_LOGLEVEL_DEBUG,
"unable to reverse, using reversed_cwd=%s",
virtual_reversed_cwd);
}
}
/* put the reversed CWD to our one-slot cache: */
if (luaif->host_cwd) free(luaif->host_cwd);
Expand Down

0 comments on commit 101799b

Please sign in to comment.