On Sat, Aug 05, 2006 at 05:03:32AM +0200, Michał Bartoszkiewicz wrote:
> Options -h and -H to du are broken in lftp 3.5.2:
> lftp [EMAIL PROTECTED]:~/.dodatek> du -s downloads/
> 1401508 downloads/
> lftp [EMAIL PROTECTED]:~/.dodatek> du -sh downloads/
> 1 downloads/
> lftp [EMAIL PROTECTED]:~/.dodatek> du -sH downloads/
> 1 downloads/
Here is the fix.
--
Alexander.
Index: FileSetOutput.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/FileSetOutput.cc,v
retrieving revision 1.40
diff -u -p -r1.40 FileSetOutput.cc
--- FileSetOutput.cc 24 Jul 2006 08:50:19 -0000 1.40
+++ FileSetOutput.cc 7 Aug 2006 08:19:06 -0000
@@ -118,7 +118,7 @@ void FileSetOutput::print(FileSet &fs, O
&& (f->defined&f->SIZE)) {
char buffer[128];
sprintf(sz, "%8s ",
- human_readable (f->size, buffer, human_ceiling, 1,
+ human_readable (f->size, buffer, human_opts, 1,
output_block_size? output_block_size:1024));
} else {
sprintf(sz, "%8s ", ""); /* pad */
Index: FileSetOutput.h
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/FileSetOutput.h,v
retrieving revision 1.16
diff -u -p -r1.16 FileSetOutput.h
--- FileSetOutput.h 6 Feb 2006 10:57:24 -0000 1.16
+++ FileSetOutput.h 7 Aug 2006 08:18:35 -0000
@@ -64,13 +64,15 @@ public:
bool list_directories;
bool need_exact_time;
int output_block_size;
+ int human_opts;
FileSet::sort_e sort;
FileSetOutput(): classify(0), width(0), color(false), mode(NONE),
pat(NULL), time_fmt(0), basenames(false), showdots(false),
quiet(false), patterns_casefold(false), sort_casefold(false),
sort_reverse(false),
sort_dirs_first(false), size_filesonly(false), single_column(false),
- list_directories(false), need_exact_time(false), output_block_size(0),
sort(FileSet::BYNAME) { }
+ list_directories(false), need_exact_time(false), output_block_size(0),
+ human_opts(0), sort(FileSet::BYNAME) { }
~FileSetOutput() { xfree(pat); xfree(time_fmt); }
FileSetOutput(const FileSetOutput &cp);
const FileSetOutput &operator = (const FileSetOutput &cp);
Index: FindJobDu.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/FindJobDu.cc,v
retrieving revision 1.9
diff -u -p -r1.9 FindJobDu.cc
--- FindJobDu.cc 24 Jul 2006 08:50:19 -0000 1.9
+++ FindJobDu.cc 7 Aug 2006 08:27:10 -0000
@@ -48,6 +48,7 @@ FinderJob_Du::FinderJob_Du(FileAccess *s
max_print_depth = -1;
print_totals = false;
output_block_size = 1024;
+ human_opts = 0;
all_files = false;
separate_dirs = false;
file_count = false;
@@ -177,7 +178,7 @@ void FinderJob_Du::print_size (long long
/* We get blocks in bytes, since we don't know the remote system's
* block size. */
buf->Format("%s\t%s\n",
- human_readable (n_blocks, buffer, human_ceiling, 1, output_block_size),
+ human_readable (n_blocks, buffer, human_opts, 1, output_block_size),
string);
}
Index: FindJobDu.h
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/FindJobDu.h,v
retrieving revision 1.3
diff -u -p -r1.3 FindJobDu.h
--- FindJobDu.h 1 Dec 2003 07:46:19 -0000 1.3
+++ FindJobDu.h 7 Aug 2006 08:23:23 -0000
@@ -31,6 +31,7 @@ class FinderJob_Du : public FinderJob
int max_print_depth;
bool print_totals;
int output_block_size;
+ int human_opts;
bool all_files;
bool separate_dirs;
bool file_count;
@@ -60,7 +61,7 @@ public:
int Done();
void PrintTotals() { print_totals=true; }
- void SetBlockSize(int n) { output_block_size = n; }
+ void SetBlockSize(int n,int ho) { output_block_size = n; human_opts = ho; }
void PrintDepth(int n) { max_print_depth = n; }
void AllFiles() { all_files=true; }
void SeparateDirs() { separate_dirs=true; }
Index: commands.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/commands.cc,v
retrieving revision 1.258
diff -u -p -r1.258 commands.cc
--- commands.cc 24 Jul 2006 08:50:20 -0000 1.258
+++ commands.cc 7 Aug 2006 08:39:16 -0000
@@ -37,6 +37,7 @@
# include <dlfcn.h>
#endif
#include <mbswidth.h>
+#include <human.h>
#include "CmdExec.h"
#include "GetJob.h"
@@ -1422,30 +1423,43 @@ CMD(ls)
/* this seems to belong here more than in FileSetOutput.cc ... */
const char *FileSetOutput::parse_argv(ArgV *a)
{
+ enum {
+ OPT_BLOCK_SIZE,
+ OPT_DATE,
+ OPT_FILESIZE,
+ OPT_GROUP,
+ OPT_LINKCOUNT,
+ OPT_LINKS
+ OPT_PERMS,
+ OPT_SI,
+ OPT_SORT,
+ OPT_TIME_STYLE,
+ OPT_USER,
+ };
static struct option cls_options[] = {
{"basename",no_argument,0,'B'},
{"directory",no_argument,0,'d'},
{"human-readable",no_argument,0,'h'},
- {"block-size",required_argument,0,0},
- {"si",no_argument,0,0},
+ {"block-size",required_argument,0,OPT_BLOCK_SIZE},
+ {"si",no_argument,0,OPT_SI},
{"classify",no_argument,0,'F'},
{"long",no_argument,0,'l'},
{"quiet",no_argument,0,'q'},
- {"size", no_argument,0,'s'}, /* show size */
- {"filesize", no_argument,0,0}, /* for files only */
- {"nocase", no_argument,0,'i'},
- {"sortnocase", no_argument,0,'I'},
- {"dirsfirst", no_argument,0,'D'},
- {"time-style", required_argument,0,256+'T'},
+ {"size",no_argument,0,'s'}, /* show size */
+ {"filesize",no_argument,0,OPT_FILESIZE}, /* for files only */
+ {"nocase",no_argument,0,'i'},
+ {"sortnocase",no_argument,0,'I'},
+ {"dirsfirst",no_argument,0,'D'},
+ {"time-style",required_argument,0,OPT_TIME_STYLE},
- {"sort", required_argument,0, 0},
+ {"sort",required_argument,0,OPT_SORT},
{"reverse",no_argument,0,'r'},
- {"user", no_argument,0, 0},
- {"group", no_argument,0, 0},
- {"perms", no_argument,0, 0},
- {"date", no_argument,0, 0},
- {"linkcount", no_argument,0, 0},
- {"links", no_argument,0, 0},
+ {"user",no_argument,0,OPT_USER},
+ {"group",no_argument,0,OPT_GROUP},
+ {"perms",no_argument,0,OPT_PERMS},
+ {"date",no_argument,0,OPT_DATE},
+ {"linkcount",no_argument,0,OPT_LINKCOUNT},
+ {"links",no_argument,0,OPT_LINKS},
{0,0,0,0}
};
@@ -1455,34 +1469,42 @@ const char *FileSetOutput::parse_argv(Ar
while((opt=a->getopt_long(":1BdFhiklqsDISrt", cls_options, &longopt))!=EOF)
{
switch(opt) {
- case 0:
- if(!strcmp(cls_options[longopt].name, "sort")) {
- if(!strcasecmp(optarg, "name")) sort = FileSet::BYNAME;
- else if(!strcasecmp(optarg, "size")) sort = FileSet::BYSIZE;
- else if(!strcasecmp(optarg, "date")) sort = FileSet::BYDATE;
- else if(!strcasecmp(optarg, "time")) sort = FileSet::BYDATE;
- else return _("invalid argument for `--sort'");
- } else if(!strcmp(cls_options[longopt].name, "filesize")) {
- size_filesonly = true;
- } else if(!strcmp(cls_options[longopt].name, "user")) {
- mode |= USER;
- } else if(!strcmp(cls_options[longopt].name, "group")) {
- mode |= GROUP;
- } else if(!strcmp(cls_options[longopt].name, "perms")) {
- mode |= PERMS;
- } else if(!strcmp(cls_options[longopt].name, "date")) {
- mode |= DATE;
- } else if(!strcmp(cls_options[longopt].name, "linkcount")) {
- mode |= NLINKS;
- } else if(!strcmp(cls_options[longopt].name, "links")) {
- mode |= LINKS;
- } else if(!strcmp(cls_options[longopt].name, "si")) {
- output_block_size = -1000;
- } else if(!strcmp(cls_options[longopt].name, "block-size")) {
- if(!isdigit(optarg[0]))
- return _("invalid block size");
- output_block_size = atoi(optarg);
- }
+ case OPT_SORT:
+ if(!strcasecmp(optarg, "name")) sort = FileSet::BYNAME;
+ else if(!strcasecmp(optarg, "size")) sort = FileSet::BYSIZE;
+ else if(!strcasecmp(optarg, "date")) sort = FileSet::BYDATE;
+ else if(!strcasecmp(optarg, "time")) sort = FileSet::BYDATE;
+ else return _("invalid argument for `--sort'");
+ break;
+ case OPT_FILESIZE:
+ size_filesonly = true;
+ break;
+ case OPT_USER:
+ mode |= USER;
+ break;
+ case OPT_GROUP:
+ mode |= GROUP;
+ break;
+ case OPT_PERMS:
+ mode |= PERMS;
+ break;
+ case OPT_DATE:
+ mode |= DATE;
+ break;
+ case OPT_LINKCOUNT:
+ mode |= NLINKS;
+ break;
+ case OPT_LINKS:
+ mode |= LINKS;
+ break;
+ case OPT_SI:
+ output_block_size = 1;
+ human_opts=human_autoscale|human_SI;
+ break;
+ case OPT_BLOCK_SIZE:
+ if(!isdigit(optarg[0]))
+ return _("invalid block size");
+ output_block_size = atoi(optarg);
break;
case('1'):
single_column = true;
@@ -1494,7 +1516,8 @@ const char *FileSetOutput::parse_argv(Ar
list_directories = true;
break;
case('h'):
- output_block_size = -1024;
+ output_block_size = 1;
+ human_opts=human_autoscale|human_SI|human_base_1024;
break;
case('l'):
long_list();
@@ -1529,7 +1552,7 @@ const char *FileSetOutput::parse_argv(Ar
case('r'):
sort_reverse = true;
break;
- case(256+'T'):
+ case OPT_TIME_STYLE:
time_style=optarg;
break;
@@ -2878,13 +2901,17 @@ CMD(find)
CMD(du)
{
+ enum {
+ OPT_BLOCK_SIZE,
+ OPT_EXCLUDE
+ };
static struct option du_options[]=
{
{"all",no_argument,0,'a'},
/* alias: both GNU-like max-depth and lftp-like maxdepth;
* only document one of them. */
{"bytes",no_argument,0,'b'},
- {"block-size",required_argument,0,0},
+ {"block-size",required_argument,0,OPT_BLOCK_SIZE},
{"maxdepth",required_argument,0,'d'},
{"total",no_argument,0,'c'},
{"max-depth",required_argument,0,'d'},
@@ -2895,7 +2922,7 @@ CMD(du)
{"megabytes",required_argument,0,'m'},
{"separate-dirs",no_argument,0,'S'},
{"summarize",no_argument,0,'s'},
- {"exclude",required_argument,0,0},
+ {"exclude",required_argument,0,OPT_EXCLUDE},
{0,0,0,0}
};
int maxdepth = -1;
@@ -2907,6 +2934,7 @@ CMD(du)
bool all_files=false;
bool file_count=false;
const char *exclude=0;
+ int human_opts=0;
exit_code=1;
@@ -2939,10 +2967,12 @@ CMD(du)
file_count=true;
break;
case 'h':
- blocksize = -1024;
+ blocksize=1;
+ human_opts|=human_autoscale|human_SI|human_base_1024;
break;
case 'H':
- blocksize = -1000;
+ blocksize=1;
+ human_opts |= human_autoscale|human_SI;
break;
case 'k': /* the default; here for completeness */
blocksize = 1024;
@@ -2956,23 +2986,17 @@ CMD(du)
case 'S':
separate_dirs = true;
break;
- case 0:
- if(!strcmp(du_options[longopt].name, "block-size")) {
- if(!isdigit(optarg[0]) || atoi(optarg) == 0)
- {
- eprintf(_("%s: invalid block size `%s'\n"),op,optarg);
- return 0;
- }
-
- blocksize = atoi(optarg);
- break;
- }
-
- if(!strcmp(du_options[longopt].name, "exclude")) {
- exclude=optarg;
- break;
+ case OPT_BLOCK_SIZE:
+ if(!isdigit(optarg[0]) || atoi(optarg) == 0)
+ {
+ eprintf(_("%s: invalid block size `%s'\n"),op,optarg);
+ return 0;
}
- /* fallthrough */
+ blocksize = atoi(optarg);
+ break;
+ case OPT_EXCLUDE:
+ exclude=optarg;
+ break;
case '?':
default:
eprintf(_("Usage: %s [options] <dirs>\n"),op);
@@ -3008,7 +3032,7 @@ CMD(du)
FinderJob_Du *j=new class FinderJob_Du(session->Clone(),args,output);
args=0;
j->PrintDepth(maxdepth);
- j->SetBlockSize(blocksize);
+ j->SetBlockSize(blocksize,human_opts);
if(print_totals)
j->PrintTotals();
if(all_files)