As others have mentioned, you can hold down the option key (⌥) while choosing Empty Trash to ignore locked files. But if they're actually in use, you have a few options:
- Figure out which applications are using the files with
lsof
and grep
(e.g. lsof | grep in_use_filename
), and quit those applications
- Use the
rm
command to delete ~/.Trash/*
- Choose "Secure Empty Trash…" from the Finder menu. If you have a lot of files, this will take a while, since it actually overwrites the contents before deleting... but if you don't, it's an easy way to ignore the purportedly in-use files and delete them anyway.
The directory entry is just a pointer to an inode. The inode contains the meta-information about the file (other than the name), and pointers to the file's data (if any). When you start to copy a file you get a handle to the inode.
The operating system maintains a count of references to the inode. As long as there are references to the inode, the inode and the file's data are kept. Once all references to the the inode are removed, the inode is and the space required by the file is released.
As you have the file open for copying it will be kept until your process closes the file. This should occur when the file transfer finishes, and will happen if the copy process fails. If the file transfer fails part way through and you have deleted all hard links to the file, you will be unable to successfully restart the transfer.
EDIT: As other have noted, file moves on the same device are done without moving the data. Instead a new directory entry is created in the destination directory, and the original directory entry is removed.
It is possible to have multiple directory entries for the same file. These are called hard links. They are created by making a new directory entry for the file without removing the original entry. The file system's inode has a reference count to record the number of directory entries pointing to the file.
EDIT2: If the process crashes or is killed, the file will be cleanly removed as the in memory access count will be reduced to zero. This is the action that occurs when the the program ends normally.
In the case of a power fail or other unorderly system shutdown, the disk will need an fsck
(file system check) before it can be fully mounted. Depending on the state of the on-disk inode and directory structures, the space will be recovered, the file will remain in the directory, or a new entry will be made in the lost+found
directory. The results will depend on which changes have been flushed to disk or written to the file systems journal.
Best Answer
As I understand it, the torrent file contains a hash for each piece of the file you are downloading. It simply checks the hashes for each piece you think you have, against the checklist. Much like when you download a torrent, any piece that does not match is discarded.
In more detail, based off the bitorrent specifications you have your downloaded file, 'piece length' and 'pieces'. Piece length is the size of each piece, and pieces is simply the sha1 sum of each piece, appended to the previous piece to form a long string.
To simplify things, lets assume you preallocated the file, and you basically have a large 'padded' file of equal length to your source file. First, based off piece length, the program gets the first n bits of the file, and does a SHA1 sum. It then compares the SHA1 sum of the file to the corresponding part of 'pieces'. If they match, we're good. Else, its marked as no good and discarded.