From 34d5f06f39ef4051793b8200be0cc532ebf63c8f Mon Sep 17 00:00:00 2001 From: tenox Date: Sun, 15 Jan 2017 03:23:33 -0800 Subject: git subdirectory fix --- dialogs.c | 3 ++- fileio.c | 36 +++++++++++++++++++++++------------- wfm.h | 6 ++++-- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/dialogs.c b/dialogs.c index 7926a26..66a3705 100644 --- a/dialogs.c +++ b/dialogs.c @@ -260,6 +260,7 @@ void about(void) { "GCC: %s
\n" "Server: %s
\n" "User Agent: %s
\n" + "NAME_MAX: %d
\n" "JavaScript Level: %d
\n" "Git Support: %s (%s)
\n" " 

\n" @@ -278,7 +279,7 @@ void about(void) { " \n" "\n" "\n\n", - ICONSURL, TAGLINE, VERSION, __DATE__, __TIME__, __VERSION__, cgiServerSoftware, cgiUserAgent, js, + ICONSURL, TAGLINE, VERSION, __DATE__, __TIME__, __VERSION__, cgiServerSoftware, cgiUserAgent, NAME_MAX, js, #ifdef WFMGIT "Yes" #else diff --git a/fileio.c b/fileio.c index 78044b0..08589b0 100644 --- a/fileio.c +++ b/fileio.c @@ -82,7 +82,7 @@ void receivefile(void) { cgiFormFileClose(input); fclose(output); - revup_commit("Receive File"); + change_commit("Receive File"); redirect("%s?highlight=%s&directory=%s&token=%s", cgiScriptName, virt_filename_urlencoded, virt_dirname_urlencoded, token); @@ -104,7 +104,7 @@ void mkfile(void) { fclose(output); - revup_commit("New File"); + change_commit("New File"); redirect("%s?highlight=%s&directory=%s&token=%s", cgiScriptName, virt_filename_urlencoded, virt_dirname_urlencoded, token); @@ -205,7 +205,7 @@ void edit_save(void) { free(buff); - revup_commit("Editor Save"); + change_commit("Editor Save"); redirect("%s?highlight=%s&directory=%s&token=%s", cgiScriptName, virt_filename_urlencoded, virt_dirname_urlencoded, token); } @@ -267,7 +267,7 @@ void fileio_delete(void) { else { if(unlink(phys_filename)!=0) error("Unable to remove file.
%s", strerror(errno)); - delete_commit("Delete File"); + delete_commit("Delete File"); } } @@ -304,15 +304,25 @@ void delete(void) { void fileio_move(void) { char final_destination[PHYS_DESTINATION_SIZE]={0}; struct stat fileinfo; + int move=0; + + // If moving file to a different directory we need to append the original file name to destination + if( stat(phys_destination, &fileinfo)==0 && S_ISDIR(fileinfo.st_mode) ) { + snprintf(final_destination, sizeof(final_destination), "%s/%s", phys_destination, virt_filename); + move=1; + } else { + strncpy(final_destination, phys_destination, sizeof(final_destination)); + move=0; + } + + if(rename(phys_filename, final_destination)!=0) + error("Unable to move file.
[%d: %s]
[SRC=%s] [DST=%s]", errno, strerror(errno), phys_filename, final_destination); + + if(move) + move_commit("Move File"); + else + rename_commit("Rename File"); - // If moving file to a different directory we need to append the original file name - if( stat(phys_destination, &fileinfo)==0 && S_ISDIR(fileinfo.st_mode) ) - snprintf(final_destination, sizeof(final_destination), "%s/%s", phys_destination, virt_filename); - else - strncpy(final_destination, phys_destination, sizeof(final_destination)); - - if(rename(phys_filename, final_destination)!=0) - error("Unable to move file.
[%d: %s]
[SRC=%s] [DST=%s]", errno, strerror(errno), phys_filename, final_destination); } // @@ -347,7 +357,7 @@ void move(void) { // Recursive Dir Size // // NOTE: will not count directories starting with . (dot) -// so size of git repo will not show here... +// so size of git repo will not be included off_t du(char *pdir) { DIR *dir; struct dirent *direntry; diff --git a/wfm.h b/wfm.h index aa43724..87bf7f6 100644 --- a/wfm.h +++ b/wfm.h @@ -63,7 +63,7 @@ char VALIDCHRS_DIR[256]; // above + / #define SHM_SIZE 16 -#define VIRT_DIRNAME_SIZE NAME_MAX +#define VIRT_DIRNAME_SIZE NAME_MAX // around 255 #define PHYS_DIRNAME_SIZE 1024 #define VIRT_FILENAME_SIZE NAME_MAX #define PHYS_FILENAME_SIZE 1280 @@ -149,6 +149,8 @@ void html_title(char *); void singleprompt_ui(char *); char *url_encode(char *); char *url_decode(char *); -int revup_commit(char *); +int change_commit(char *); int delete_commit(char *); +int rename_commit(char *); +int move_commit(char *); int repo_check(void); \ No newline at end of file -- cgit v1.2.3