Re: a program to delete duplicate files
Patrick Useldinger wrote:[color=blue]
> John Machin wrote:
>[color=green]
> > Maybe I was wrong: lawyers are noted for irritating precision. You
> > meant to say in your own defence: "If there are *any* number (n >=[/color][/color]
2)[color=blue][color=green]
> > of identical hashes, you'd still need to *RE*-read and *compare*[/color][/color]
....".[color=blue]
>
> Right, that is what I meant.
>[color=green]
> > 2. As others have explained, with a decent hash function, the
> > probability of a false positive is vanishingly small. Further,[/color][/color]
nobody[color=blue][color=green]
> > in their right mind [1] would contemplate automatically deleting[/color][/color]
n-1[color=blue][color=green]
> > out of a bunch of n reportedly duplicate files without further
> > investigation. Duplicate files are usually (in the same directory[/color][/color]
with[color=blue][color=green]
> > different names or in different-but-related directories with the[/color][/color]
same[color=blue][color=green]
> > names) and/or (have a plausible explanation for how they were
> > duplicated) -- the one-in-zillion-chance false-positive should[/color][/color]
stand[color=blue][color=green]
> > out as implausible.[/color]
>
> Still, if you can get it 100% right automatically, why would you[/color]
bother[color=blue]
> checking manually?[/color]
A human in their right mind is required to decide what to do with the
duplicates. The proponents of hashing -- of which I'm not one -- would
point out that any false-positives would be picked up as part of the
human scrutiny.
[color=blue]
> Why get back to argments like "impossible ",
> "implausibl e", "can't be" if you can have a simple and correct answer[/color]
-[color=blue]
> yes or no?[/color]
Oh yeah, "the computer said so, it must be correct". Even with your
algorithm, I would be investigating cases where files were duplicates
but there was nothing in the names or paths that suggested how that
might have come about.
[color=blue]
>
> Anyway, fdups does not do anything else than report duplicates.
> Deleting, hardlinking or anything else might be an option depending[/color]
on[color=blue]
> the context in which you use fdups, but then we'd have to discuss the[/color]
[color=blue]
> context. I never assumed any context, in order to keep it as[/color]
universal[color=blue]
> as possible.[/color]
That's very good, but it wasn't under contention.
[color=blue]
>[color=green]
> > Different subject: maximum number of files that can be open at[/color][/color]
once. I[color=blue][color=green]
> > raised this issue with you because I had painful memories of having[/color][/color]
to[color=blue][color=green]
> > work around max=20 years ago on MS-DOS and was aware that this[/color][/color]
magic[color=blue][color=green]
> > number was copied blindly from early Unix. I did tell you that
> > empirically I could get 509 successful opens on Win 2000 [add 3 for
> > stdin/out/err to get a plausible number] -- this seems high enough[/color][/color]
to[color=blue][color=green]
> > me compared to the likely number of files with the same size -- but[/color][/color]
you[color=blue][color=green]
> > might like to consider a fall-back detection method instead of just
> > quitting immediately if you ran out of handles.[/color]
>
> For the time being, the additional files will be ignored, and a[/color]
warning[color=blue]
> is issued. fdups does not quit, why are you saying this?[/color]
I beg your pardon, I was wrong. Bad memory. It's the case of running
out of the minuscule buffer pool that you allocate by default where it
panics and pulls the sys.exit(1) rip-cord.
[color=blue]
>
> A fallback solution would be to open the file before every _block_[/color]
read,[color=blue]
> and close it afterwards.[/color]
Ugh. Better use more memory, so less blocks!!
[color=blue]
> In my mind, it would be a command-line option,
> because it's difficult to determine the number of available file[/color]
handles[color=blue]
> in a multitasking environment.[/color]
The pythonic way is to press ahead optimistically and recover if you
get bad news.
[color=blue]
>
> Not difficult to implement, but I first wanted to refactor the code[/color]
so[color=blue]
> that it's a proper class that can be used in other Python programs,[/color]
as[color=blue]
> you also asked.[/color]
I didn't "ask"; I suggested. I would never suggest a
class-for-classes-sake. You had already a singleton class; why
another". What I did suggest was that you provide a callable interface
that returned clusters of duplicates [so that people could do their own
thing instead of having to parse your file output which contains a
mixture of warning & info messages and data].
[color=blue]
> That is what I have sent you tonight. It's not that I
> don't care about the file handle problem, it's just that I do changes[/color]
by[color=blue]
> (my own) priority.
>[color=green]
> > You wrote at some stage in this thread that (a) this caused[/color][/color]
problems on[color=blue][color=green]
> > Windows and (b) you hadn't had any such problems on Linux.
> >
> > Re (a): what evidence do you have?[/color]
>
> I've had the case myself on my girlfriend's XP box. It was certainly
> less than 500 files of the same length.[/color]
Interesting. Less on XP than on 2000? Maybe there's a machine-wide
limit, not a per-process limit, like the old DOS max=20. What else was
running at the time?
[color=blue]
>[color=green]
> > Re (b): famous last words! How long would it take you to do a test[/color][/color]
and[color=blue][color=green]
> > announce the margin of safety that you have?[/color]
>
> Sorry, I do not understand what you mean by this.[/color]
Test:
!for k in range(1000):
! open('foo' + str(k), 'w')
Announce:
"I can open A files at once on box B running os C. The most files of
the same length that I have seen is D. The ratio A/D is small enough
not to worry."
Cheers,
John
Patrick Useldinger wrote:[color=blue]
> John Machin wrote:
>[color=green]
> > Maybe I was wrong: lawyers are noted for irritating precision. You
> > meant to say in your own defence: "If there are *any* number (n >=[/color][/color]
2)[color=blue][color=green]
> > of identical hashes, you'd still need to *RE*-read and *compare*[/color][/color]
....".[color=blue]
>
> Right, that is what I meant.
>[color=green]
> > 2. As others have explained, with a decent hash function, the
> > probability of a false positive is vanishingly small. Further,[/color][/color]
nobody[color=blue][color=green]
> > in their right mind [1] would contemplate automatically deleting[/color][/color]
n-1[color=blue][color=green]
> > out of a bunch of n reportedly duplicate files without further
> > investigation. Duplicate files are usually (in the same directory[/color][/color]
with[color=blue][color=green]
> > different names or in different-but-related directories with the[/color][/color]
same[color=blue][color=green]
> > names) and/or (have a plausible explanation for how they were
> > duplicated) -- the one-in-zillion-chance false-positive should[/color][/color]
stand[color=blue][color=green]
> > out as implausible.[/color]
>
> Still, if you can get it 100% right automatically, why would you[/color]
bother[color=blue]
> checking manually?[/color]
A human in their right mind is required to decide what to do with the
duplicates. The proponents of hashing -- of which I'm not one -- would
point out that any false-positives would be picked up as part of the
human scrutiny.
[color=blue]
> Why get back to argments like "impossible ",
> "implausibl e", "can't be" if you can have a simple and correct answer[/color]
-[color=blue]
> yes or no?[/color]
Oh yeah, "the computer said so, it must be correct". Even with your
algorithm, I would be investigating cases where files were duplicates
but there was nothing in the names or paths that suggested how that
might have come about.
[color=blue]
>
> Anyway, fdups does not do anything else than report duplicates.
> Deleting, hardlinking or anything else might be an option depending[/color]
on[color=blue]
> the context in which you use fdups, but then we'd have to discuss the[/color]
[color=blue]
> context. I never assumed any context, in order to keep it as[/color]
universal[color=blue]
> as possible.[/color]
That's very good, but it wasn't under contention.
[color=blue]
>[color=green]
> > Different subject: maximum number of files that can be open at[/color][/color]
once. I[color=blue][color=green]
> > raised this issue with you because I had painful memories of having[/color][/color]
to[color=blue][color=green]
> > work around max=20 years ago on MS-DOS and was aware that this[/color][/color]
magic[color=blue][color=green]
> > number was copied blindly from early Unix. I did tell you that
> > empirically I could get 509 successful opens on Win 2000 [add 3 for
> > stdin/out/err to get a plausible number] -- this seems high enough[/color][/color]
to[color=blue][color=green]
> > me compared to the likely number of files with the same size -- but[/color][/color]
you[color=blue][color=green]
> > might like to consider a fall-back detection method instead of just
> > quitting immediately if you ran out of handles.[/color]
>
> For the time being, the additional files will be ignored, and a[/color]
warning[color=blue]
> is issued. fdups does not quit, why are you saying this?[/color]
I beg your pardon, I was wrong. Bad memory. It's the case of running
out of the minuscule buffer pool that you allocate by default where it
panics and pulls the sys.exit(1) rip-cord.
[color=blue]
>
> A fallback solution would be to open the file before every _block_[/color]
read,[color=blue]
> and close it afterwards.[/color]
Ugh. Better use more memory, so less blocks!!
[color=blue]
> In my mind, it would be a command-line option,
> because it's difficult to determine the number of available file[/color]
handles[color=blue]
> in a multitasking environment.[/color]
The pythonic way is to press ahead optimistically and recover if you
get bad news.
[color=blue]
>
> Not difficult to implement, but I first wanted to refactor the code[/color]
so[color=blue]
> that it's a proper class that can be used in other Python programs,[/color]
as[color=blue]
> you also asked.[/color]
I didn't "ask"; I suggested. I would never suggest a
class-for-classes-sake. You had already a singleton class; why
another". What I did suggest was that you provide a callable interface
that returned clusters of duplicates [so that people could do their own
thing instead of having to parse your file output which contains a
mixture of warning & info messages and data].
[color=blue]
> That is what I have sent you tonight. It's not that I
> don't care about the file handle problem, it's just that I do changes[/color]
by[color=blue]
> (my own) priority.
>[color=green]
> > You wrote at some stage in this thread that (a) this caused[/color][/color]
problems on[color=blue][color=green]
> > Windows and (b) you hadn't had any such problems on Linux.
> >
> > Re (a): what evidence do you have?[/color]
>
> I've had the case myself on my girlfriend's XP box. It was certainly
> less than 500 files of the same length.[/color]
Interesting. Less on XP than on 2000? Maybe there's a machine-wide
limit, not a per-process limit, like the old DOS max=20. What else was
running at the time?
[color=blue]
>[color=green]
> > Re (b): famous last words! How long would it take you to do a test[/color][/color]
and[color=blue][color=green]
> > announce the margin of safety that you have?[/color]
>
> Sorry, I do not understand what you mean by this.[/color]
Test:
!for k in range(1000):
! open('foo' + str(k), 'w')
Announce:
"I can open A files at once on box B running os C. The most files of
the same length that I have seen is D. The ratio A/D is small enough
not to worry."
Cheers,
John
Comment