CodeSOD: The Destination Dir
Darren is supporting a Delphi application in the current decade. Which is certainly a situation to be in. He writes:
I keep trying to get out of doing maintenance on legacy Delphi applications, but they keep pulling me back in.
The bit of code Darren sends us isn't the largest WTF, but it's a funny mistake, and it's a funny mistake that's been sitting in the codebase for decades at this point. And as we all know, jokes only get funnier with age.
FileName := DestDir + ExtractFileName(FileName);if FileExists(DestDir + ExtractFileName(FileName)) thenbegin ...end;
This code is inside of a module that copies a file from a remote server to the local host. It starts by sanitizing the FileName, using ExtractFileName to strip off any path components, and replace them with DestDir, storing the result in the FileName variable.
And they liked doing that so much, they go ahead and do it again in the if statement, repeating the exact same process.
Darren writes:
As Homer Simpson said "Lather, rinse, and repeat. Always repeat."