1 // $Id: getvserverbyctx-compat.hc,v 1.3 2004/06/27 13:01:28 ensc Exp $ --*- c -*--
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);
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)
72 if (revdir==0) revdir = DEFAULT_PKGSTATEREVDIR;
75 vcCfgStyle cur_style = vcCFG_NONE;
76 size_t l = strlen(revdir);
78 char path[l + sizeof(unsigned int)*3 + 3];
82 l1 = utilvserver_fmt_uint(path+l+1, ctx);
85 if (style==0 || *style==vcCFG_AUTO) {
86 if (access(path, F_OK)==0) cur_style = vcCFG_RECENT_FULL;
87 else cur_style = vcCFG_LEGACY;
93 case vcCFG_RECENT_SHORT :
94 case vcCFG_RECENT_FULL :
95 // check if expected ctx == actual ctx
96 if (vc_getVserverCtx(path, vcCFG_RECENT_FULL, false, 0)!=ctx) return 0;
98 if (style) *style = vcCFG_RECENT_FULL;
100 // TODO: handle legacy
103 char * tmp = handleLegacy(ctx);
105 *style = vcCFG_LEGACY;