3 // Copyright (C) 2003 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.
25 #include "pathconfig.h"
26 #include "compat-c99.h"
31 #ifdef VC_ENABLE_API_COMPAT
33 #include <sys/types.h>
37 handleLegacy(xid_t xid)
39 DIR *dir = opendir(DEFAULT_PKGSTATEDIR);
44 while ((ep=readdir(dir))!=0) {
45 char * const name = ep->d_name;
46 size_t l = name ? strlen(name) : 0;
49 if (l<=4 || strcmp(name+l-4, ".ctx")!=0) continue;
51 cur_xid = vc_getVserverCtx(name, vcCFG_LEGACY, false, 0, vcCTX_XID);
52 if (cur_xid!=xid) continue;
54 result = strdup(name);
63 handleLegacy(xid_t UNUSED xid)
70 vc_getVserverByCtx_compat(xid_t ctx, vcCfgStyle *style, char const *revdir,
73 if (revdir==0) revdir = DEFAULT_PKGSTATEREVDIR;
76 vcCfgStyle cur_style = vcCFG_NONE;
77 size_t l = strlen(revdir);
79 char path[l + sizeof(unsigned int)*3 + 3];
83 l1 = utilvserver_fmt_uint(path+l+1, ctx);
86 if (style==0 || *style==vcCFG_AUTO) {
87 if (access(path, F_OK)==0) cur_style = vcCFG_RECENT_FULL;
88 else cur_style = vcCFG_LEGACY;
94 case vcCFG_RECENT_SHORT :
95 case vcCFG_RECENT_FULL :
96 // check if expected ctx == actual ctx (but only when this check is
98 if (validate_result &&
99 vc_getVserverCtx(path, vcCFG_RECENT_FULL, false, 0, vcCTX_XID)!=ctx) return 0;
101 if (style) *style = vcCFG_RECENT_FULL;
103 // TODO: handle legacy
106 char * tmp = handleLegacy(ctx);
108 *style = vcCFG_LEGACY;