Example #1
0
int bbdocument_deletecoll(char collection[]) {

	int LotNr;
	int i;
	char FilePath[512];
	char IndexPath[512];
	char DictionaryPath[512];
	FILE *fh;

	debug("Deleting collection: \"%s\"\n",collection);

	LotNr = 1;
	while((fh =lotOpenFileNoCasheByLotNr(LotNr,"reposetory","r",'s',collection)) != NULL) {
		GetFilPathForLot(FilePath,LotNr,collection);

		fclose(fh);

		rrmdir(FilePath);

		++LotNr;
	}

	for (i=0; i < 64; i++) {
		GetFilePathForIindex(FilePath,IndexPath,i,"Main","aa",collection);
		#ifdef DEBUG
		printf("FilePath: %s\nIndexPath: %s\n",FilePath,IndexPath);
		#endif

		if ((unlink(IndexPath) != 1) && (errno != ENOENT)) { //ENOENT=No such file or directory. Viser ikke feil hvis filen ikke fantes. Det er helt normalt
                        perror("remove IndexPath");
                }


		GetFilePathForIDictionary(FilePath,DictionaryPath,i,"Main","aa",collection);
		#ifdef DEBUG
		printf("FilePath: %s\nDictionaryPath: %s\n",FilePath,DictionaryPath);
		#endif

		if ((unlink(DictionaryPath) != 0) && (errno != ENOENT)) {//ENOENT=No such file or directory. Viser ikke feil hvis filen ikke fantes. Det er helt normalt
                        perror("remove DictionaryPath");
                }
	}

	//sletter i userToSubname.db
        struct userToSubnameDbFormat userToSubnameDb;

        if (!userToSubname_open(&userToSubnameDb,'w')) {
                printf("can't open users.db\n");
        }
        else {
		userToSubname_deletecol(&userToSubnameDb,collection);

                userToSubname_close(&userToSubnameDb);
        }

	return 1;
}
Example #2
0
int main (int argc, char *argv[]) {
	FILE *fp;
	char username[MAX_USER_NAME_LEN], username_last[MAX_USER_NAME_LEN];
	DB *dbp = NULL;
	DBT key, data;
	int ret;
	//int *dbpp;

	struct userToSubnameDbFormat userToSubnameDb;

	if (argc != 3) {
		printf("usgae ./mergeUserToSubname lotnr subname\n");
		exit(1);
	}

	int lotNr = atoi(argv[1]);
	char *subname = argv[2];

	if (!userToSubname_open(&userToSubnameDb,'w')) {
		perror("userToSubname_open");
		exit(1);
	}

	if ((fp = lotOpenFileNoCasheByLotNr(lotNr,"acllist","rb", 's',subname) ) == NULL) {
		perror("acllist");
	}
	else {
		username_last[0] = '\0';
		while(fgets(username,sizeof(username),fp) != NULL) {
			chomp(username);
			if (strcmp(username_last,username) != 0) {
				printf("username \"%s\"\n",username);

				userToSubname_add(&userToSubnameDb,username,subname);
				strcpy(username_last,username);
			}
		}

		fclose(fp);

	}


	if ((fp = lotOpenFileNoCasheByLotNr(lotNr,"aclcollectionlist","rb", 's',subname) ) == NULL) {
		perror("aclcollectionlist");
	}
	else {
		username_last[0] = '\0';
		while(fgets(username,sizeof(username),fp) != NULL) {
			chomp(username);
			if (strcmp(username_last,username) != 0) {
				printf("username \"%s\"\n",username);

				userToSubname_add(&userToSubnameDb,username,subname);
				strcpy(username_last,username);
			}
		}

		fclose(fp);

	}


	userToSubname_close(&userToSubnameDb);

	/*
	//temp
	userToSubname_open(&dbpp);
	char buf[128] = "*****";
	userToSubname_getsubnamesAsString(&dbpp,"Everyone",buf);
	printf("aa  subnames \"%s\"\n",buf);
	userToSubname_close(&dbpp);
	*/

	return 0;

}