How Unrar Handles Insufficient Permissions
When a user attempts to extract an archive using unrar
without the appropriate account permissions, the utility detects the
restriction, halts the extraction of the affected items, and outputs a
descriptive error message to the console. Rather than failing silently
or corrupting the destination directory, unrar skips
unauthorized write actions, leaves inaccessible files untouched, and
terminates with a non-zero exit status to indicate an incomplete
operation.
Target Directory Write Failures
If the user account running the unrar command does not
possess write privileges in the destination directory,
unrar cannot create the necessary file structures. In this
scenario:
- The utility immediately throws an error:
Cannot create <filename>followed byPermission denied. - If subdirectories within the archive need to be created, directory creation fails first, causing all subsequent files destined for that folder to fail extraction.
- The command continues attempting to extract remaining files if any target destinations are accessible, but it will generally fail entirely if the root extraction path itself is blocked.
Overwriting Existing Protected Files
When an archive contains a file with the same name as an existing file in the target directory that the current user cannot modify or overwrite:
- Without forced overwrite flags,
unrarusually prompts the user on how to proceed. - If forced overwriting is specified (such as using the
-o+switch) or confirmed via prompt, the operating system denies the file replacement request. unrarflags the operation as a failure for that specific item, outputs a write error, and skips to the next file in the archive.
Restoration of Archived Permissions and Ownership
RAR archives created on Unix-like platforms can store file attributes, ownerships (UID/GID), and POSIX permissions. When extracting such archives:
- Standard, unprivileged users cannot change file ownership to match
the archived user (
chownoperations require superuser/root status). In these cases,unrarsilently assigns ownership to the current extracting user while maintaining standard permission masks. - If the archive tries to apply strict read-only permissions to a
newly created folder during extraction,
unrarattempts to extract the directory's contents before locking the folder permissions to prevent locking itself out during the process.
Exit Codes and Script Handling
To alert automated scripts and systems to permission failures,
unrar sets a return code upon completion. Instead of
returning 0 (Successful operation), it typically
returns:
- Exit Code 6 (Open error): Commonly triggered when
unrarcannot open or create a target file due to permission restrictions or access lockouts. - Exit Code 1 (Non-fatal error): Occurs if minor errors, warnings, or skipped files occurred throughout the process.