- inode->i_attributes = FILE_ATTRIBUTE_REPARSE_POINT;
- inode->i_reparse_tag = WIM_IO_REPARSE_TAG_SYMLINK;
-
- /* The idea here is to call readlink() to get the UNIX target of
- * the symbolic link, then turn the target into a reparse point
- * data buffer that contains a relative or absolute symbolic
- * link (NOT a junction point or *full* path symbolic link with
- * drive letter).
- */
- deref_name_len = readlink(path, deref_name_buf,
- sizeof(deref_name_buf) - 1);
- if (deref_name_len >= 0) {
- deref_name_buf[deref_name_len] = '\0';
- DEBUG("Read symlink `%s'", deref_name_buf);
- ret = inode_set_symlink(inode, deref_name_buf,
- lookup_table, NULL);
- if (ret == 0) {
- /* Unfortunately, Windows seems to have the concept of
- * "file" symbolic links as being different from
- * "directory" symbolic links... so
- * FILE_ATTRIBUTE_DIRECTORY needs to be set on the
- * symbolic link if the *target* of the symbolic link is
- * a directory. */
- struct stat stbuf;
- if (stat(path, &stbuf) == 0 && S_ISDIR(stbuf.st_mode))
- inode->i_attributes |= FILE_ATTRIBUTE_DIRECTORY;
- }
- } else {
- ERROR_WITH_ERRNO("Failed to read target of "
- "symbolic link `%s'", path);
- ret = WIMLIB_ERR_READLINK;
- }
- return ret;
-}
-
-static int
-unix_build_dentry_tree_recursive(struct wim_dentry **root_ret,
- char *path,
- size_t path_len,
- struct wim_lookup_table *lookup_table,
- struct wim_inode_table *inode_table,
- const struct wimlib_capture_config *config,
- int add_image_flags,
- wimlib_progress_func_t progress_func)
-{
- struct wim_dentry *root = NULL;
- int ret = 0;
- struct wim_inode *inode;
-
- if (exclude_path(path, path_len, config, true)) {
- if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_ROOT) {
- ERROR("Cannot exclude the root directory from capture");
- ret = WIMLIB_ERR_INVALID_CAPTURE_CONFIG;
- goto out;
- }
- if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_EXCLUDE_VERBOSE)
- && progress_func)
- {
- union wimlib_progress_info info;
- info.scan.cur_path = path;
- info.scan.excluded = true;
- progress_func(WIMLIB_PROGRESS_MSG_SCAN_DENTRY, &info);
- }
- goto out;
- }
-
- if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE)
- && progress_func)
- {
- union wimlib_progress_info info;
- info.scan.cur_path = path;
- info.scan.excluded = false;
- progress_func(WIMLIB_PROGRESS_MSG_SCAN_DENTRY, &info);
- }
-
- /* UNIX version of capturing a directory tree */
- struct stat stbuf;
- int (*stat_fn)(const char *restrict, struct stat *restrict);
- if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE)
- stat_fn = stat;
- else
- stat_fn = lstat;
-
- ret = (*stat_fn)(path, &stbuf);
- if (ret != 0) {
- ERROR_WITH_ERRNO("Failed to stat `%s'", path);
- goto out;
- }
-
- if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_ROOT) &&
- !S_ISDIR(stbuf.st_mode))
- {
- /* Do a dereference-stat in case the root is a symbolic link.
- * This case is allowed, provided that the symbolic link points
- * to a directory. */
- ret = stat(path, &stbuf);
- if (ret != 0) {
- ERROR_WITH_ERRNO("Failed to stat `%s'", path);
- ret = WIMLIB_ERR_STAT;
- goto out;
- }
- if (!S_ISDIR(stbuf.st_mode)) {
- ERROR("`%s' is not a directory", path);
- ret = WIMLIB_ERR_NOTDIR;
- goto out;
- }
- }
- if (!S_ISREG(stbuf.st_mode) && !S_ISDIR(stbuf.st_mode)
- && !S_ISLNK(stbuf.st_mode)) {
- ERROR("`%s' is not a regular file, directory, or symbolic link.",
- path);
- ret = WIMLIB_ERR_SPECIAL_FILE;
- goto out;
- }
-
- ret = inode_table_new_dentry(inode_table,
- path_basename_with_len(path, path_len),
- stbuf.st_ino,
- stbuf.st_dev,
- &root);
- if (ret)
- goto out;
-
- inode = root->d_inode;
-
- if (inode->i_nlink > 1) /* Already captured this inode? */
- goto out;
-
-#ifdef HAVE_STAT_NANOSECOND_PRECISION
- inode->i_creation_time = timespec_to_wim_timestamp(stbuf.st_mtim);
- inode->i_last_write_time = timespec_to_wim_timestamp(stbuf.st_mtim);
- inode->i_last_access_time = timespec_to_wim_timestamp(stbuf.st_atim);
-#else
- inode->i_creation_time = unix_timestamp_to_wim(stbuf.st_mtime);
- inode->i_last_write_time = unix_timestamp_to_wim(stbuf.st_mtime);
- inode->i_last_access_time = unix_timestamp_to_wim(stbuf.st_atime);
-#endif
- inode->i_resolved = 1;
- if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_UNIX_DATA) {
- ret = inode_set_unix_data(inode, stbuf.st_uid,
- stbuf.st_gid,
- stbuf.st_mode,
- lookup_table,
- UNIX_DATA_ALL | UNIX_DATA_CREATE);
- if (ret)
- goto out;