X

OS X Lion Finder bug deletes moved files

It's an unusual bug, but it could still happen to you. Here's how to dodge it.

Topher Kessler MacFixIt Editor
Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.
Topher Kessler
3 min read

When you move files from one location to another in the OS X Finder, if their names are the same as existing files or folders, the system will ask you whether you wish to keep both files, replace the existing file, or cancel the move operation. If you replace the file, then the one you are moving should be the only one left in the new location; however, a bug in the Finder in OS X might result in both files being deleted.

Earlier today, Mac OS X Hints posted steps that show the Finder deleting both the original and new items that are moved to the same location on the drive:

  1. Create a folder anywhere (the Desktop is fine) and call it "test"
  2. Create a file within that folder and also call it test (you can use the Terminal's touch command to do this if you are familiar with it). Keep in mind the file has to be the exact same name as the folder, so remove any extensions such as ".txt" from it.
  3. Drag the file from within the test folder to the same folder containing the test folder (such as the Desktop)
  4. When prompted whether to replace the file, chose the option to replace it.

When you follow these steps, the system will delete both files. While the person who submitted this issue to Mac OS X Hints claimed that this bug also happens if you choose the option to keep both files, I have not been able to get this to happen in testing. Instead, when keeping both files, the Finder renames the moved file to "test copy" as it should.

Finder replacement warning
Normally OS X will display this message if you try to replace a folder with its contents; however, the bug in Lion bypasses this check and allows the replace to occur. Screenshot by Topher Kessler

The problem here is that the Finder's check for replacing folders with a file it contains is not working properly. Normally, if you drag a file or folder to be next to its parent directory as is done in the steps above, if the dragged item is the same name as the parent directory, you will get an error stating, "the folder NAME cannot be replaced by an item it contains." This prevents the initial deletion of the folder from also removing the file being moved; however, it appears this check is not working in current builds of OS X Lion, which may lead to the loss of the directory and its contents, including the dragged file.

While this is an issue to be cautious of, unless you specifically move a file within a folder's hierarchy to replace the folder itself, then it is likely not a bug you will run into. Additionally, the data loss here is primarily to the file being dragged and not to the deleted directory tree since these steps are intended to delete the tree in the first place.

Luckily, if you have Time Machine enabled, you can likely recover the lost file by browsing for it in the Time Machine backups at the location where the directory was lost. Hopefully Apple will address this problem in an update to Lion, but until then, avoiding these steps is the only way to ensure that you don't lose any files in this manner.



Questions? Comments? Have a fix? Post them below or e-mail us!
Be sure to check us out on Twitter and the CNET Mac forums.