3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <sys/types.h>
24 #define CONCAT_TWO_ARGS(BUF, LHS,RHS) \
25 size_t BUF ## l1 = strlen(LHS); \
26 size_t BUF ## l2 = strlen(RHS); \
27 char BUF[BUF##l1 + BUF##l2 + 2]; \
29 memcpy(BUF, LHS, BUF##l1 + 1); \
31 BUF[ BUF##l1 ] = '/'; \
32 memcpy(BUF+ BUF##l1 + 1, RHS, BUF##l2 + 1); \
36 mkdir2(char const *lhs, char const *rhs, int mode)
38 CONCAT_TWO_ARGS(buf, lhs, rhs);
39 return mkdir(buf, mode);
43 setIAttr2(char const *lhs, char const *rhs, int flags)
45 CONCAT_TWO_ARGS(buf, lhs, rhs);
47 return vc_set_iattr(buf, 0, flags, VC_IMMUTABLE_ALL);
51 symlink2(char const *old_lhs, char const *old_rhs,
52 char const *new_lhs, char const *new_rhs)
54 CONCAT_TWO_ARGS(old_buf, old_lhs, old_rhs);
57 CONCAT_TWO_ARGS(new_buf, new_lhs, new_rhs);
58 return symlink(old_buf, new_buf);
62 #undef CONCAT_TWO_ARGS
65 vc_createSkeleton_full(char const *id, char const *name, int flags)
67 if (mkdir(id, 0755)==-1) return -1;
69 if (mkdir2(id, "apps", 0755)==-1 ||
70 ((flags&vcSKEL_INTERFACES) && mkdir2(id, "interfaces", 755)==-1) ||
71 ((flags&vcSKEL_PKGMGMT) && (
72 mkdir2(id, "apps/pkgmgmt", 0755)==-1)))
76 char const *basedir = CONFDIR "/.defaults/run";
78 if (!utilvserver_isDirectory(basedir, true)) basedir = DEFAULT_PKGSTATEDIR;
79 if (!utilvserver_isDirectory(basedir, true)) break;
81 if (symlink2(basedir, name, id, "run")==-1)
87 while (flags&vcSKEL_PKGMGMT) {
88 char const *basedir = CONFDIR "/.defaults/apps/pkgmgmt/base";
90 if (!utilvserver_isDirectory(basedir, true)) basedir = DEFAULT_VSERVERPKGDIR;
91 if (!utilvserver_isDirectory(basedir, true)) break;
93 if (mkdir2(basedir, name, 0755)==-1 ||
94 symlink2(basedir, name, id, "apps/pkgmgmt/base")==-1)
100 while (flags&vcSKEL_FILESYSTEM) {
101 char const *basedir = CONFDIR "/.defaults/vdirbase";
103 if (!utilvserver_isDirectory(basedir, true)) basedir = DEFAULT_VSERVERDIR;
104 if (!utilvserver_isDirectory(basedir, true)) break;
106 if (mkdir2(basedir, name, 0755)==-1 ||
107 setIAttr2(basedir, name, 0)==-1 ||
108 symlink2(basedir, name, id, "vdir")==-1)