Directory Modification Times and Permissions (GNU tar 1.34)

Next: Writing to Standard Output, Previous: Setting Access Permissions, Up: Writing [Contents][Index]

#### Directory Modification Times and Permissions

After successfully extracting a file member, GNU `tar` normally restores its permissions and modification times, as described in the previous sections. This cannot be done for directories, because after extracting a directory `tar` will almost certainly extract files into that directory and this will cause the directory modification time to be updated. Moreover, restoring that directory permissions may not permit file creation within it. Thus, restoring directory permissions and modification times must be delayed at least until all files have been extracted into that directory. GNU `tar` restores directories using the following approach.

The extracted directories are created with the mode specified in the archive, as modified by the umask of the user, which gives sufficient permissions to allow file creation. The meta-information about the directory is recorded in the temporary list of directories. When preparing to extract next archive member, GNU `tar` checks if the directory prefix of this file contains the remembered directory. If it does not, the program assumes that all files have been extracted into that directory, restores its modification time and permissions and removes its entry from the internal list. This approach allows to correctly restore directory meta-information in the majority of cases, while keeping memory requirements sufficiently small. It is based on the fact, that most `tar` archives use the predefined order of members: first the directory, then all the files and subdirectories in that directory.

However, this is not always true. The most important exception are incremental archives (see Incremental Dumps). The member order in an incremental archive is reversed: first all directory members are stored, followed by other (non-directory) members. So, when extracting from incremental archives, GNU `tar` alters the above procedure. It remembers all restored directories, and restores their meta-data only after the entire archive has been processed. Notice, that you do not need to specify any special options for that, as GNU `tar` automatically detects archives in incremental format.

There may be cases, when such processing is required for normal archives too. Consider the following example:

    $ tar --no-recursion -cvf archive \
        foo foo/file1 bar bar/file foo/file2
    foo/
    foo/file1
    bar/
    bar/file
    foo/file2

During the normal operation, after encountering `bar` GNU `tar` will assume that all files from the directory `foo` were already extracted and will therefore restore its timestamp and permission bits. However, after extracting `foo/file2` the directory timestamp will be offset again.

To correctly restore directory meta-information in such cases, use the `--delay-directory-restore` command line option:

`--delay-directory-restore`

  Delays restoring of the modification times and permissions of extracted directories until the end of extraction. This way, correct meta-information is restored even if the archive has unusual member ordering.

`--no-delay-directory-restore`

  Cancel the effect of the previous `--delay-directory-restore`. Use this option if you have used `--delay-directory-restore` in `TAR_OPTIONS` variable (see TAR_OPTIONS) and wish to temporarily disable it.

Next: Writing to Standard Output, Previous: Setting Access Permissions, Up: Writing [Contents][Index]