static int arch_add(const char *const *argv) { struct dpkg_arch *arch; const char *archname = *argv++; if (archname == NULL || *argv) badusage(_("--%s takes exactly one argument"), cipaction->olong); dpkg_arch_load_list(); arch = dpkg_arch_add(archname); switch (arch->type) { case DPKG_ARCH_NATIVE: case DPKG_ARCH_FOREIGN: break; case DPKG_ARCH_ILLEGAL: ohshit(_("architecture '%s' is illegal: %s"), archname, dpkg_arch_name_is_illegal(archname)); default: ohshit(_("architecture '%s' is reserved and cannot be added"), archname); } dpkg_arch_save_list(); return 0; }
const char * pkg_spec_is_illegal(struct pkg_spec *ps) { static char msg[1024]; const char *emsg; if (!ps->name_is_pattern && (emsg = pkg_name_is_illegal(ps->name))) { const char *arch_sep; /* Only check for DPKG_ARCH_NONE, because for everything else * we want to see the passed package specification, even if * the architecture is empty. */ if (ps->arch->type == DPKG_ARCH_NONE) arch_sep = ""; else arch_sep = ":"; snprintf(msg, sizeof(msg), _("illegal package name in specifier '%s%s%s': %s"), ps->name, arch_sep, ps->arch->name, emsg); return msg; } if ((!ps->arch_is_pattern && ps->arch->type == DPKG_ARCH_ILLEGAL) || ps->arch->type == DPKG_ARCH_EMPTY) { emsg = dpkg_arch_name_is_illegal(ps->arch->name); snprintf(msg, sizeof(msg), _("illegal architecture name in specifier '%s:%s': %s"), ps->name, ps->arch->name, emsg); return msg; } /* If we have been requested a single instance, check that the * package does not contain other instances. */ if (!ps->arch_is_pattern && ps->flags & PKG_SPEC_ARCH_SINGLE) { struct pkgset *set; set = pkg_db_find_set(ps->name); /* Single instancing only applies with no architecture. */ if (ps->arch->type == DPKG_ARCH_NONE && pkgset_installed_instances(set) > 1) { snprintf(msg, sizeof(msg), _("ambiguous package name '%s' with more " "than one installed instance"), ps->name); return msg; } } return NULL; }
const char * pkg_spec_is_illegal(struct pkg_spec *ps) { static char msg[1024]; const char *emsg; if (!ps->name_is_pattern && (emsg = pkg_name_is_illegal(ps->name))) { snprintf(msg, sizeof(msg), _("illegal package name in specifier '%s%s%s': %s"), ps->name, (ps->arch->type != DPKG_ARCH_NONE) ? ":" : "", ps->arch->name, emsg); return msg; } if ((!ps->arch_is_pattern && ps->arch->type == DPKG_ARCH_ILLEGAL) || ps->arch->type == DPKG_ARCH_EMPTY) { emsg = dpkg_arch_name_is_illegal(ps->arch->name); snprintf(msg, sizeof(msg), _("illegal architecture name in specifier '%s:%s': %s"), ps->name, ps->arch->name, emsg); return msg; } /* If we have been requested a single instance, check that the * package does not contain other instances. */ if (!ps->arch_is_pattern && ps->flags & PKG_SPEC_ARCH_SINGLE) { struct pkgset *set; set = pkg_db_find_set(ps->name); /* Single instancing only applies with no architecture. */ if (ps->arch->type == DPKG_ARCH_NONE && pkgset_installed_instances(set) > 1) { snprintf(msg, sizeof(msg), _("ambiguous package name '%s' with more " "than one installed instance"), ps->name); return msg; } } return NULL; }
static void test_dpkg_arch_name_is_illegal(void) { /* Test invalid architecture names. */ test_fail(dpkg_arch_name_is_illegal("") == NULL); test_fail(dpkg_arch_name_is_illegal("-i386") == NULL); test_fail(dpkg_arch_name_is_illegal(" i386") == NULL); test_fail(dpkg_arch_name_is_illegal(":any") == NULL); test_fail(dpkg_arch_name_is_illegal("amd64_test") == NULL); test_fail(dpkg_arch_name_is_illegal("i386:test") == NULL); test_fail(dpkg_arch_name_is_illegal("i386 amd64") == NULL); test_fail(dpkg_arch_name_is_illegal("i386,amd64") == NULL); test_fail(dpkg_arch_name_is_illegal("i386|amd64") == NULL); /* Test valid architecture names. */ test_pass(dpkg_arch_name_is_illegal("i386") == NULL); test_pass(dpkg_arch_name_is_illegal("amd64") == NULL); test_pass(dpkg_arch_name_is_illegal("hurd-i386") == NULL); test_pass(dpkg_arch_name_is_illegal("kfreebsd-i386") == NULL); test_pass(dpkg_arch_name_is_illegal("kfreebsd-amd64") == NULL); test_pass(dpkg_arch_name_is_illegal("ia64") == NULL); test_pass(dpkg_arch_name_is_illegal("alpha") == NULL); test_pass(dpkg_arch_name_is_illegal("armel") == NULL); test_pass(dpkg_arch_name_is_illegal("hppa") == NULL); test_pass(dpkg_arch_name_is_illegal("mips") == NULL); test_pass(dpkg_arch_name_is_illegal("mipsel") == NULL); test_pass(dpkg_arch_name_is_illegal("powerpc") == NULL); test_pass(dpkg_arch_name_is_illegal("s390") == NULL); test_pass(dpkg_arch_name_is_illegal("sparc") == NULL); }