Author: sjg
Date: Sat Nov  3 00:10:30 2012
New Revision: 242501
URL: http://svn.freebsd.org/changeset/base/242501

Log:
  If no contents keyword is specified, the default for files is
  the named file.
  
  Approved by:  marcel (mentor)

Modified:
  head/usr.sbin/makefs/mtree.c

Modified: head/usr.sbin/makefs/mtree.c
==============================================================================
--- head/usr.sbin/makefs/mtree.c        Fri Nov  2 23:25:52 2012        
(r242500)
+++ head/usr.sbin/makefs/mtree.c        Sat Nov  3 00:10:30 2012        
(r242501)
@@ -135,6 +135,47 @@ mtree_warning(const char *fmt, ...)
        fputc('\n', stderr);
 }
 
+#ifndef MAKEFS_MAX_TREE_DEPTH
+# define MAKEFS_MAX_TREE_DEPTH (MAXPATHLEN/2)
+#endif
+
+/* construct path to node->name */
+static char *
+mtree_file_path(fsnode *node)
+{
+       fsnode *pnode;
+       struct sbuf *sb;
+       char *res, *rp[MAKEFS_MAX_TREE_DEPTH];
+       int depth;
+
+       depth = 0;
+       rp[depth] = node->name;
+       for (pnode = node->parent; pnode && depth < MAKEFS_MAX_TREE_DEPTH;
+            pnode = pnode->parent) {
+               if (strcmp(pnode->name, ".") == 0)
+                       break;
+               rp[++depth] = pnode->name;
+       }
+       
+       sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
+       if (sb == NULL) {
+               errno = ENOMEM;
+               return (NULL);
+       }
+       while (depth > 0) {
+               sbuf_cat(sb, rp[depth--]);
+               sbuf_putc(sb, '/');
+       }
+       sbuf_cat(sb, rp[depth]);
+       sbuf_finish(sb);
+       res = strdup(sbuf_data(sb));
+       sbuf_delete(sb);
+       if (res == NULL)
+               errno = ENOMEM;
+       return res;
+
+}
+
 /* mtree_resolve() sets errno to indicate why NULL was returned. */
 static char *
 mtree_resolve(const char *spec, int *istemp)
@@ -706,6 +747,12 @@ read_mtree_keywords(FILE *fp, fsnode *no
                        return (0);
                }
                type = S_IFREG;
+       } else if (node->type != 0) {
+               type = node->type;
+               if (type == S_IFREG) {
+                       /* the named path is the default contents */
+                       node->contents = mtree_file_path(node);
+               }
        } else
                type = (node->symlink != NULL) ? S_IFLNK : S_IFDIR;
 
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to