Hi!

Currently, lftp assumes that the user will have a directory in $HOME
named .lftp for storing configuration files and auxilliary files.  The
handling of this directory was done separately in a couple of places in
the code, so I unified it in one function, get_home() and used that
instead.  As a bonus, the user may now set the $LFTP_HOME environment
variable to another directory so that lftp files don't necessarily need
to live in ~/.lftp.  I would very much appreciate having this variable,
as I like to keep my ~ tidy.  The patch isn’t brilliant, but I didn’t
want to change more than the obvious stuff.  I would suggest that
another function that provided an interface to the file storage was
written, e.g., char *find_file_in_home(const char *file) that would take
stuff like "rc" and "history" and give back a string like "~/.lftp/rc"
and such.

Thank you very much for a nice ftp client,
        nikolai

-- 
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
diff -ru lftp-3.3.0.old/doc/lftp.1 lftp-3.3.0.new/doc/lftp.1
--- lftp-3.3.0.old/doc/lftp.1   2005-08-12 09:29:18.000000000 +0200
+++ lftp-3.3.0.new/doc/lftp.1   2005-10-12 13:31:10.888147344 +0200
@@ -1510,6 +1510,9 @@
 Used to set initial net:no-proxy variable.
 .IP "\fBLFTP_MODULE_PATH\fP"
 Used to set initial module:path variable.
+.IP "\fBLFTP_HOME\fP"
+Used to locate the directory that stores user-specific configuration files.  If
+unset, ~/.lftp will be used.
 
 .SH FILES
 .TP
diff -ru lftp-3.3.0.old/src/ChangeLog lftp-3.3.0.new/src/ChangeLog
--- lftp-3.3.0.old/src/ChangeLog        2005-08-12 09:05:19.000000000 +0200
+++ lftp-3.3.0.new/src/ChangeLog        2005-10-12 13:31:26.137829040 +0200
@@ -1,3 +1,11 @@
+2005-10-12  Nikolai Weibull <[EMAIL PROTECTED]>
+
+       * src/boomark.cc,src/commands.cc,src/history.cc,src/import-ncftp,
+         src/import-netscape,src/lftp.cc,src/lftp_rl.cc: Added handling for
+         $LFTP_HOME environment variable, so that users can override the
+         default of $HOME/.lftp.  Implemented the get_home() function in
+         src/lftp.cc to do this and updated all users of getenv("HOME").
+
 2005-08-12  Alexander V. Lukyanov <[EMAIL PROTECTED]>
 
        * parsecmd.cc: return PARSE_AGAIN if the command ends with \0,
diff -ru lftp-3.3.0.old/src/bookmark.cc lftp-3.3.0.new/src/bookmark.cc
--- lftp-3.3.0.old/src/bookmark.cc      2005-06-23 08:39:03.000000000 +0200
+++ lftp-3.3.0.new/src/bookmark.cc      2005-10-12 13:18:31.487593776 +0200
@@ -34,12 +34,14 @@
 
 ResDecl 
res_auto_sync("bmk:auto-sync","yes",ResMgr::BoolValidate,ResMgr::NoClosure);
 
+extern char *get_home();
+
 Bookmark::Bookmark()
 {
-   const char *home=getenv("HOME");
+   const char *home=get_home();
    if(home==0)
       home="";
-   const char *add="/.lftp/bookmarks";
+   const char *add="bookmarks";
    bm_file=xstrdup(home,+strlen(add));
    strcat(bm_file,add);
 
diff -ru lftp-3.3.0.old/src/commands.cc lftp-3.3.0.new/src/commands.cc
--- lftp-3.3.0.old/src/commands.cc      2005-08-03 09:12:47.000000000 +0200
+++ lftp-3.3.0.new/src/commands.cc      2005-10-12 13:31:44.330063400 +0200
@@ -2652,7 +2652,7 @@
    else if(!strcasecmp(op,"edit"))
    {
       lftp_bookmarks.Remove(""); // force bookmark file creation
-      parent->PrependCmd("shell \"/bin/sh -c 'exec ${EDITOR:-vi} 
$HOME/.lftp/bookmarks'\"\n");
+      parent->PrependCmd("shell \"/bin/sh -c 'exec ${EDITOR:-vi} 
${LFTP_HOME:-$HOME/.lftp}/bookmarks'\"\n");
    }
    else if(!strcasecmp(op,"import"))
    {
diff -ru lftp-3.3.0.old/src/history.cc lftp-3.3.0.new/src/history.cc
--- lftp-3.3.0.old/src/history.cc       2005-08-03 09:12:48.000000000 +0200
+++ lftp-3.3.0.new/src/history.cc       2005-10-12 13:20:44.784329592 +0200
@@ -31,6 +31,8 @@
 
 #define super KeyValueDB
 
+extern char *get_home();
+
 History::History()
 {
    full=0;
@@ -38,10 +40,10 @@
    fd=-1;
    modified=false;
 
-   const char *home=getenv("HOME");
+   const char *home=get_home();
    if(home==0)
       home="";
-   const char *add="/.lftp/cwd_history";
+   const char *add="/cwd_history";
    file=xstrdup(home,+strlen(add));
    strcat(file,add);
 }
diff -ru lftp-3.3.0.old/src/import-ncftp lftp-3.3.0.new/src/import-ncftp
--- lftp-3.3.0.old/src/import-ncftp     1998-10-15 13:33:14.000000000 +0200
+++ lftp-3.3.0.new/src/import-ncftp     2005-10-12 13:31:49.107337144 +0200
@@ -7,7 +7,7 @@
 set -e
 
 NCFTP="$HOME/.ncftp/bookmarks"
-OLD="$HOME/.lftp/bookmarks"
+OLD="${LFTP_HOME:-$HOME/.lftp}/bookmarks"
 NEW="$OLD.new.$$"
 
 grep "," "$NCFTP" | cut -d, -f1,2,3,6 | sed \
diff -ru lftp-3.3.0.old/src/import-netscape lftp-3.3.0.new/src/import-netscape
--- lftp-3.3.0.old/src/import-netscape  1998-10-15 13:33:14.000000000 +0200
+++ lftp-3.3.0.new/src/import-netscape  2005-10-12 13:31:52.890761976 +0200
@@ -7,7 +7,7 @@
 set -e
 
 NS="$HOME/.netscape/bookmarks.html"
-OLD="$HOME/.lftp/bookmarks"
+OLD="${LFTP_HOME:-$HOME/.lftp}/bookmarks"
 NEW="$OLD.new.$$"
 
 prepend_hash()
diff -ru lftp-3.3.0.old/src/lftp.cc lftp-3.3.0.new/src/lftp.cc
--- lftp-3.3.0.old/src/lftp.cc  2005-05-18 15:25:17.000000000 +0200
+++ lftp-3.3.0.new/src/lftp.cc  2005-10-12 13:31:58.122966560 +0200
@@ -59,6 +59,32 @@
 CmdExec         *top_exec;
 
 
+char *get_home()
+{
+   static char *home=NULL;
+
+   if(home)
+      return home;
+
+   home=getenv("LFTP_HOME");
+   if(!home)
+   {
+      home=getenv("HOME");
+      if(home)
+      {
+         char *tmp=(char*)malloc(strlen(home)+9+1);
+         sprintf(tmp,"%s/.lftp",home);
+         home=tmp;
+      }
+      else
+      {
+         return NULL;
+      }
+   }
+
+   mkdir(rc,0755);
+}
+
 void  hook_signals()
 {
    SignalHook::DoCount(SIGHUP);
@@ -266,11 +292,11 @@
       SignalHook::Ignore(SIGHUP);
       SignalHook::Ignore(SIGTSTP);
 
-      const char *home=getenv("HOME");
+      const char *home=get_home();
       if(home)
       {
-        char *log=(char*)alloca(strlen(home)+1+9+1);
-        sprintf(log,"%s/.lftp",home);
+        char *log=(char*)alloca(strlen(home)+1+3+1);
+        sprintf(log,"%s",home);
         if(access(log,F_OK)==-1)
            strcat(log,"_log");
         else
@@ -379,13 +405,16 @@
    {
       char *rc=(char*)alloca(strlen(home)+9+1);
 
-      // create lftp own directory
-      sprintf(rc,"%s/.lftp",home);
-      mkdir(rc,0755);
-
       sprintf(rc,"%s/.lftprc",home);
       source_if_exist(top_exec,rc);
-      sprintf(rc,"%s/.lftp/rc",home);
+   }
+
+   home=get_home();
+   if(home)
+   {
+      char *rc=(char*)alloca(strlen(home)+3+1);
+
+      sprintf(rc,"%s/rc",home);
       source_if_exist(top_exec,rc);
    }
 
diff -ru lftp-3.3.0.old/src/lftp_rl.c lftp-3.3.0.new/src/lftp_rl.c
--- lftp-3.3.0.old/src/lftp_rl.c        2004-11-03 09:37:44.000000000 +0100
+++ lftp-3.3.0.new/src/lftp_rl.c        2005-10-12 13:24:32.029783032 +0200
@@ -183,13 +183,15 @@
    rl_set_prompt(p);
 }
 
+extern char *get_home();
+
 static char *lftp_history_file;
 void lftp_rl_read_history()
 {
    if(!lftp_history_file)
    {
-      const char *home=getenv("HOME");
-      const char *add="/.lftp/rl_history";
+      const char *home=get_home();
+      const char *add="/rl_history";
       if(!home) home="";
       lftp_history_file=(char*)malloc(strlen(home)+strlen(add)+1);
       strcat(strcpy(lftp_history_file,home),add);

Reply via email to