Commit 4a398d61 authored by kollo's avatar kollo

improved dupdel.bas

parent 6365fc1c
......@@ -55,12 +55,12 @@ WHILE LEN(PARAM$(i))
INC i
WEND
IF not EXIST(masterpath$) OR NOT EXIST(slavepath$)
IF NOT EXIST(masterpath$) OR NOT EXIST(slavepath$)
PRINT "You need to specify two paths with --master an --slave"
PRINT "Abort."
QUIT
ENDIF
IF masterpath$=slavepath$ or inode(masterpath$)=inode(slavepath$)
IF masterpath$=slavepath$ OR inode(masterpath$)=inode(slavepath$)
PRINT "Master and Slave paths are the same!"
PRINT "Abort."
QUIT
......@@ -84,6 +84,8 @@ DIM u%(anzfiles)
FOR i=0 TO anzfiles-1
u%(i)=i
NEXT i
PRINT "-s-";
FLUSH
SORT filelen(),anzfiles,u%()
' Now list all files found (with full path name)
......@@ -94,7 +96,7 @@ IF anzfiles>0
' PRINT str$(filelen(i));" ";files$(u%(i))
NEXT i
ENDIF
PRINT "Found ";anzfiles;" files in ";anzdir;" directories."
PRINT " ";anzfiles;" files in ";anzdir;" directories."
anzmasterfiles=anzfiles
PRINT "Slave: ";slavepath$;" --> ";
......@@ -104,6 +106,8 @@ DIM u%(anzfiles)
FOR i=0 TO anzfiles-1
u%(i)=i
NEXT i
PRINT "-s-";
FLUSH
SORT filelen(),anzfiles,u%()
' Now list all files found (with full path name)
......@@ -114,12 +118,11 @@ IF anzfiles>0
' PRINT str$(filelen(i));" ";files$(u%(i))
NEXT i
ENDIF
PRINT "Found ";anzfiles;" files in ";anzdir;" directories."
PRINT " ";anzfiles;" files in ";anzdir;" directories."
anzslavefiles=anzfiles
PRINT "compare..."
DIM candidate$(10000)
DIM match$(10000)
lastidx=0
startidx=0
startidx2=0
......@@ -137,6 +140,12 @@ FOR i=startidx TO anzslavefiles-1
IF verbose>1
PRINT "Try: ";slavefile$(i);" ";
PRINT "last idx=";lastidx;"/";anzmasterfiles
ELSE
IF TIMER-matchtime>2
matchtime=TIMER
PRINT INT(i/anzslavefiles*100);"% ";lastidx;"/";anzmasterfiles;" ";masterlen(lastidx);" Bytes. ";chr$(13);
FLUSH
ENDIF
ENDIF
anzcan=0
anzmatch=0
......@@ -152,10 +161,12 @@ FOR i=startidx TO anzslavefiles-1
EXIT if masterlen(j)>slavelen(i)
NEXT j
IF anzcan
' PRINT "Have ";anzcan;" candidates. for ";
if anzcan>1000
PRINT chr$(9);chr$(9);"Have ";anzcan;" candidates for ";slavefile$(i);"... ";chr$(13);
FLUSH
endif
t$=system$("md5sum "+enclose$(slavefile$(i)))
SPLIT t$," ",0,t$,a$
' print t$
FOR k=0 TO anzcan-1
s$=system$("md5sum "+enclose$(candidate$(k)))
SPLIT s$," ",0,s$,a$
......@@ -163,7 +174,7 @@ FOR i=startidx TO anzslavefiles-1
IF s$=t$
' PRINT i;" ";INT(i/anzslavefiles*100);"% have match for: ";slavelen(i);" ";slavefile$(i)
' PRINT "*MATCH!*"
lastmatch=k
match$(anzmatch)=candidate$(k)
INC anzmatch
ELSE
' PRINT
......@@ -172,43 +183,45 @@ FOR i=startidx TO anzslavefiles-1
IF anzmatch
PRINT INT(i/anzslavefiles*100);"% have ";anzmatch;" matches for: ";slavelen(i);" ";slavefile$(i)
IF verbose
FOR k=0 TO anzcan-1
if k=lastmatch
PRINT "Candidates: ";candidate$(k);" (*)"
else
PRINT "Candidates: ";candidate$(k)
endif
FOR k=0 TO anzmatch-1
PRINT " "+str$(k+1)+" ";match$(k)
NEXT k
ENDIF
IF interactive
again:
PRINT "[Q] Quit , [d] delete , [l] symbolic link, ENTER do nothing"
PRINT "[Q] Quit , [d] delete , [l1...l"+STR$(anzmatch)+"] symbolic link, ENTER do nothing"
INPUT a$
IF a$="Q"
QUIT
ELSE if a$="d"
ELSE IF a$="d"
PRINT "DELETE"
KILL slavefile$(i)
ELSE if a$="l"
PRINT "SYMBOLIC LINK"
KILL slavefile$(i)
a$=candidate$(lastmatch)
if left$(a$)<>"/"
a$=dir$(0)+"/"+a$
endif
SYSTEM "ln -s "+enclose$(a$)+" "+enclose$(slavefile$(i))
ELSE if LEN(a$)
ELSE IF LEFT$(a$)="l"
idx=MAX(0,VAL(RIGHT$(a$,LEN(a$)-1))-1)
IF idx<anzmatch
PRINT "SYMBOLIC LINK --> ";idx+1
KILL slavefile$(i)
a$=match$(idx)
IF LEFT$(a$)<>"/"
a$=DIR$(0)+"/"+a$
ENDIF
SYSTEM "ln -s "+ENCLOSE$(a$)+" "+ENCLOSE$(slavefile$(i))
ELSE
PRINT "Wrong number. Again:"
GOTO again
ENDIF
ELSE IF LEN(a$)
PRINT "Unknown command. Again:"
GOTO again
ENDIF
ELSE if dokill
ELSE IF dokill
PRINT "DELETE"
KILL slavefile$(i)
ENDIF
matchtime=TIMER
ENDIF
ENDIF
NEXT i
QUIT
PROCEDURE stepdir(root$)
......@@ -223,7 +236,7 @@ PROCEDURE stepdir(root$)
WHILE dirpointer<anzdir
ON ERROR CONT ! Skip any error like permission denied or so....
a$=FSFIRST$(dirs$(dirpointer),"*")
WHILE len(a$)
WHILE LEN(a$)
SPLIT a$," ",0,typ$,name$
IF typ$="d" ! Is it a directory?
IF name$<>"." AND name$<>".."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment