View | Details | Raw Unified | Return to bug 420 | Differences between
and this patch

Collapse All | Expand All

(-)sftp-int.c.orig (-9 / +51 lines)
Lines 555-567 Link Here
555
555
556
/* sftp ls.1 replacement for directories */
556
/* sftp ls.1 replacement for directories */
557
static int
557
static int
558
do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
558
do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag,
559
    char *localpath)
559
{
560
{
560
	int n;
561
	int n;
561
	SFTP_DIRENT **d;
562
	SFTP_DIRENT **d;
563
	FILE *fp = NULL;
564
	FILE *fp1 = NULL;
565
566
	if (localpath) {
567
		fp = fopen(localpath, "w");
568
		if (!fp)
569
		{
570
			error("Can't write to file %s", localpath);
571
			return -1;
572
		}
573
	}
574
575
	if (fp)
576
		fp1 = fp;
577
	else
578
		fp1 = stdout;
562
579
563
	if ((n = do_readdir(conn, path, &d)) != 0)
580
	if ((n = do_readdir(conn, path, &d)) != 0)
581
	{
582
		if (fp) fclose(fp);
564
		return (n);
583
		return (n);
584
	}
565
585
566
	/* Count entries for sort */	
586
	/* Count entries for sort */	
567
	for (n = 0; d[n] != NULL; n++)
587
	for (n = 0; d[n] != NULL; n++)
Lines 583-598 Link Here
583
			memset(&sb, 0, sizeof(sb));
603
			memset(&sb, 0, sizeof(sb));
584
			attrib_to_stat(&d[n]->a, &sb);
604
			attrib_to_stat(&d[n]->a, &sb);
585
			lname = ls_file(fname, &sb, 1);
605
			lname = ls_file(fname, &sb, 1);
586
			printf("%s\n", lname);
606
			fprintf(fp1, "%s\n", lname);
587
			xfree(lname);
607
			xfree(lname);
588
		} else {
608
		} else {
589
			/* XXX - multicolumn display would be nice here */
609
			/* XXX - multicolumn display would be nice here */
590
			printf("%s\n", fname);
610
			fprintf(fp1, "%s\n", fname);
591
		}
611
		}
592
		
612
		
593
		xfree(fname);
613
		xfree(fname);
594
	}
614
	}
595
615
616
	if (fp) fclose(fp);
596
	free_sftp_dirents(d);
617
	free_sftp_dirents(d);
597
	return (0);
618
	return (0);
598
}
619
}
Lines 600-611 Link Here
600
/* sftp ls.1 replacement which handles path globs */
621
/* sftp ls.1 replacement which handles path globs */
601
static int
622
static int
602
do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, 
623
do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, 
603
    int lflag)
624
    int lflag, char* localpath)
604
{
625
{
605
	glob_t g;
626
	glob_t g;
606
	int i;
627
	int i;
607
	Attrib *a;
628
	Attrib *a;
608
	struct stat sb;
629
	struct stat sb;
630
	FILE *fp = NULL;
631
	FILE *fp1 = NULL;
609
632
610
	memset(&g, 0, sizeof(g));
633
	memset(&g, 0, sizeof(g));
611
634
Lines 628-637 Link Here
628
		if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) && 
651
		if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) && 
629
		    S_ISDIR(a->perm)) {
652
		    S_ISDIR(a->perm)) {
630
			globfree(&g);
653
			globfree(&g);
631
			return (do_ls_dir(conn, path, strip_path, lflag));
654
			return (do_ls_dir(conn, path, strip_path, lflag, localpath));
632
		}
655
		}
633
	}
656
	}
634
657
658
	if (localpath)
659
	{
660
		fp = fopen(localpath, "w");
661
		if (!fp)
662
		{
663
			error("Can't write to file %s", localpath);
664
			return -1;
665
		}
666
	}
667
668
	if (fp)
669
		fp1 = fp;
670
	else
671
		fp1 = stdout;
672
635
	for (i = 0; g.gl_pathv[i]; i++) {
673
	for (i = 0; g.gl_pathv[i]; i++) {
636
		char *fname, *lname;
674
		char *fname, *lname;
637
675
Lines 650-666 Link Here
650
			if (a != NULL)
688
			if (a != NULL)
651
				attrib_to_stat(a, &sb);
689
				attrib_to_stat(a, &sb);
652
			lname = ls_file(fname, &sb, 1);
690
			lname = ls_file(fname, &sb, 1);
653
			printf("%s\n", lname);
691
			fprintf(fp1, "%s\n", lname);
654
			xfree(lname);
692
			xfree(lname);
655
		} else {
693
		} else {
656
			/* XXX - multicolumn display would be nice here */
694
			/* XXX - multicolumn display would be nice here */
657
			printf("%s\n", fname);
695
			fprintf(fp1, "%s\n", fname);
658
		}
696
		}
659
		xfree(fname);
697
		xfree(fname);
660
	}
698
	}
661
699
662
	if (g.gl_pathc)
700
	if (g.gl_pathc)
663
		globfree(&g);
701
		globfree(&g);
702
	if (fp)
703
		fclose(fp);
664
704
665
	return (0);
705
	return (0);
666
}
706
}
Lines 759-764 Link Here
759
		/* Path is optional */
799
		/* Path is optional */
760
		if (get_pathname(&cp, path1))
800
		if (get_pathname(&cp, path1))
761
			return(-1);
801
			return(-1);
802
		if (get_pathname(&cp, path2))
803
			return(-1);
762
		break;
804
		break;
763
	case I_LLS:
805
	case I_LLS:
764
	case I_SHELL:
806
	case I_SHELL:
Lines 897-903 Link Here
897
		break;
939
		break;
898
	case I_LS:
940
	case I_LS:
899
		if (!path1) {
941
		if (!path1) {
900
			do_globbed_ls(conn, *pwd, *pwd, lflag);
942
			do_globbed_ls(conn, *pwd, *pwd, lflag, NULL);
901
			break;
943
			break;
902
		}
944
		}
903
		
945
		
Lines 908-914 Link Here
908
950
909
		path1 = make_absolute(path1, *pwd);
951
		path1 = make_absolute(path1, *pwd);
910
952
911
		do_globbed_ls(conn, path1, tmp, lflag);
953
		do_globbed_ls(conn, path1, tmp, lflag, path2);
912
		break;
954
		break;
913
	case I_LCHDIR:
955
	case I_LCHDIR:
914
		if (chdir(path1) == -1) {
956
		if (chdir(path1) == -1) {

Return to bug 420