Unrar Behavior When Extracting a Locked File

When unrar attempts to extract an archive to a destination where a target file already exists and is locked by another running process, the extraction cannot proceed normally due to operating system access controls. This article explains the exact errors generated by unrar, how the extraction process behaves interactively versus via command-line automation, and the state in which the files are left.

File System Access Denied

To extract an archive, unrar requests write permissions from the operating system to create or overwrite the target file. If another process has an exclusive lock on that file (common in Windows sharing violations or Unix processes holding exclusive write locks via flock), the operating system rejects the write request.

Because unrar cannot obtain a file handle with write access, it immediately halts write operations for that specific file.

Error Messages and Interactive Prompts

The resulting behavior depends on whether unrar is run in interactive mode or automated via flags:

  • Interactive Mode: If run manually in a terminal without automatic overwrite flags, unrar typically displays an error message such as Cannot create [filename] followed by Access is denied or a sharing violation warning. The utility will then pause and prompt the user with choices, usually including options to retry the operation, skip the file, rename the destination file, or abort the entire extraction.
  • Non-Interactive / Scripted Mode: If run with batch flags like -y (assume yes to all queries) or -o+ (overwrite without prompt), unrar cannot prompt for user input. It marks the operation for that file as failed, prints the access error to the standard error stream, and moves on to extract any remaining files in the archive.

Integrity of the Target and Archive Files

When this conflict occurs:

  • The locked file remains untouched: Because the operating system refused write access before unrar could modify the disk sectors, the original file currently in use by the other process is not modified, truncated, or corrupted.
  • Partial extraction files: unrar typically decompresses data to a temporary stream or directly to the target. If the file was locked prior to opening, no temporary data is written to the destination path. If a lock is somehow placed mid-extraction, unrar aborts and discards or leaves an incomplete temporary file depending on the file system state.

Process Exit Codes

Once unrar finishes processing the archive, it terminates with a non-zero exit code to signal that an error occurred. In standard WinRAR/unrar implementations:

  • An exit code of 1 indicates a non-fatal error (such as a locked file that was skipped while others succeeded).
  • An exit code of 6 indicates an open error, meaning a file could not be opened or created.
  • An exit code of 255 indicates that the user manually aborted the process when prompted.

How to Bypass the Lock

To successfully extract an archive containing a locked file, you can:

  1. Identify and close the locking process: Terminate the application holding the handle using tools like Resource Monitor or lsof.
  2. Extract to a different directory: Use the -op<path> switch to unpack the contents to an alternate directory where no file locks exist.
  3. Rename during extraction: Extract the file with a new name if running unrar interactively.