another attempt at make_absolute_path()
cover another attempt at make_absolute_path()
Here's my attempt at make_absolute_path() and friends. I think this version handles symlinks cleanly to avoid problems with '..' path elements Junio pointed out recently.
I built these with another patch I previously submitted to make git-config consistently use lockfile.c routines and tested it with the regular test suite plus some extra tests Junio sent to the list for checking git-config symlink handling.
I also built a separate executable with just the path handling routines in it and spot-checked several cases to make sure it appeared to be working as expected. ('/', loop of symlinks, lots of extra slashes, . and .. elements, etc.)
Best Regards,
Bradford
PATCH 1/2 added file path helper routines
From: Bradford C. Smith <[email protected]>
Added the following routines:
is_absolute_path()split_path()join_path()is_valid_path()make_absolute_path()
--- cache.h | 5 ++ path.c | 247 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 252 insertions(+), 0 deletions(-)
cache.h +5 -0
@@ -356,6 +356,11 @@ enum sharedrepo { };int git_config_perm (const char *var,const char *value);int adjust_shared_perm (const char *path); +int is_absolute_path (char *p); +void split_path (const char *p,char *start,char *rest); +void join_path (char *p,const char *start,const char *rest); +int is_valid_path (const char *p); +char *make_absolute_path (char *p);int safe_create_leading_directories (char *path);char *enter_repo (char *path,int strict);
path.c +247 -0
250 lines not on this page · raw message
Signature · 1 line
1.5.3.rc3.9.g9ef91
PATCH 2/2 use make_absolute_path() in lock_file()
From: Bradford C. Smith <[email protected]>
Use make_absolute_path() to get fully resolved path name for creating the lock file.
--- lockfile.c | 16 +++------------- 1 files changed, 3 insertions(+), 13 deletions(-)
lockfile.c +3 -13
@@ -28,20 +28,10 @@ static void remove_lock_file_on_signal(int signo)static int lock_file (struct lock_file *lk,const char *path) {int fd; -struct stat st; -if ((!lstat (path, &st)) &&S_ISLNK (st.st_mode)) { -ssize_t sz; -static char target[PATH_MAX ]; - sz =readlink (path, target,sizeof (target)); -if (sz <0 ) -warning ("Cannot readlink %s" , path); -else if (target[0 ] !='/' ) -warning ("Cannot lock target of relative symlink %s" , path); -else - path = target; - } -sprintf (lk->filename,"%s.lock" , path); +strcpy (lk->filename, path); +make_absolute_path (lk->filename); +strcat (lk->filename,".lock" ); fd =open (lk->filename,O_RDWR |O_CREAT |O_EXCL ,0666 );if (0 <= fd) {if (!lock_file_list) {
Signature · 1 line
1.5.3.rc3.9.g9ef91
Hi,
Quoted 9 lines · Bradford C Smith
Here's my attempt at
make_absolute_path()and friends. I think this version handles symlinks cleanly to avoid problems with '..' path elements Junio pointed out recently.I built these with another patch I previously submitted to make git-config consistently use
lockfile.croutines and tested it with the regular test suite plus some extra tests Junio sent to the list for checking git-config symlink handling.
Quoted 4 lines
I also built a separate executable with just the path handling routines in it and spot-checked several cases to make sure it appeared to be working as expected. ('/', loop of symlinks, lots of extra slashes, . and .. elements, etc.)
Heh. Just a couple of minutes after I sent my version...
Although I added tests, and you did not...
Ciao,
Dscho