Makefile: added phony target.
This commit is contained in:
parent
cda3b2c6eb
commit
5ec71fe7d2
5 changed files with 2 additions and 205 deletions
2
Makefile
2
Makefile
|
|
@ -45,9 +45,9 @@ obj += src/notify/event.o
|
|||
obj += src/notify/tree.o
|
||||
obj += src/notify/queue.o
|
||||
|
||||
obj += src/indexer.o
|
||||
obj += src/arch.o
|
||||
|
||||
.PHONY : all clean cleaner
|
||||
all : $(PROGRAM)
|
||||
|
||||
$(PROGRAM) : $(obj)
|
||||
|
|
|
|||
146
src/indexer.c
146
src/indexer.c
|
|
@ -1,146 +0,0 @@
|
|||
/* indexer.c
|
||||
*
|
||||
* (C) Copyright 2010 Henrik Hautakoski <henrik@fiktivkod.org>
|
||||
* (C) Copyright 2010 Fredric Nilsson <fredric@fiktivkod.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include "common/debug.h"
|
||||
#include "common/path.h"
|
||||
#include "output/output.h"
|
||||
#include "notify/notify.h"
|
||||
#include "notify/tree.h"
|
||||
#include "indexer.h"
|
||||
|
||||
static char *stack[256];
|
||||
static unsigned char st_size = 0;
|
||||
static struct tree *current = NULL;
|
||||
|
||||
/* REF:1 */
|
||||
static void index_entry(struct entry *ent) {
|
||||
|
||||
static char buf[1024];
|
||||
#if __DEBUG__
|
||||
printf("DEBUG: index_entry adding to db: %s %s %d\n", ent->base, ent->name, ent->dir);
|
||||
#endif
|
||||
|
||||
|
||||
// Event change, just for test.
|
||||
notify_event ev;
|
||||
|
||||
ev.path = ent->base;
|
||||
ev.filename = ent->name;
|
||||
ev.type = NOTIFY_CREATE;
|
||||
int status = output_process(&ev);
|
||||
if (0 != status)
|
||||
fprintf(stderr,"%s",output_error(status));
|
||||
|
||||
if (ent->dir) {
|
||||
memcpy(buf, ent->base, strlen(ent->base));
|
||||
memcpy(buf + strlen(ent->base), ent->name, strlen(ent->name)+1);
|
||||
notify_add_watch(buf);
|
||||
}
|
||||
|
||||
#ifdef __DEBUG__
|
||||
printf("Index: %s%s\n", ent->base, ent->name);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void add(const char *path) {
|
||||
|
||||
char *newstr;
|
||||
|
||||
if (st_size >= 255)
|
||||
return;
|
||||
|
||||
newstr = malloc(sizeof(char) * (strlen(path)+1));
|
||||
|
||||
if (newstr == NULL)
|
||||
return;
|
||||
|
||||
memcpy(newstr, path, strlen(path)+1);
|
||||
|
||||
stack[st_size] = newstr;
|
||||
|
||||
st_size++;
|
||||
}
|
||||
|
||||
/* we only shift the stack when getting the
|
||||
* next tree, so this will do for now. */
|
||||
static int rm() {
|
||||
|
||||
int i;
|
||||
|
||||
current = NULL;
|
||||
|
||||
while(current == NULL) {
|
||||
|
||||
if (st_size == 0)
|
||||
return 0;
|
||||
|
||||
current = tree_new(stack[0]);
|
||||
|
||||
free(stack[0]);
|
||||
|
||||
st_size--;
|
||||
|
||||
for(i=0; i < st_size; i++)
|
||||
stack[i] = stack[i+1];
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void indexer_register(const char *base, const char *name) {
|
||||
|
||||
char *fullpath = path_normalize(base, name, 1);
|
||||
|
||||
if (!indexer_pending()) {
|
||||
#if __DEBUG__
|
||||
printf("sched: adding current index: %s\n", fullpath);
|
||||
#endif
|
||||
current = tree_new(fullpath);
|
||||
free(fullpath);
|
||||
return;
|
||||
}
|
||||
|
||||
#if __DEBUG__
|
||||
printf("sched: scheduling index: %s\n", fullpath);
|
||||
#endif
|
||||
|
||||
add(fullpath);
|
||||
}
|
||||
|
||||
void indexer_run(unsigned int num) {
|
||||
|
||||
struct entry *ent;
|
||||
|
||||
int i;
|
||||
|
||||
for(i=0; i < num; i++) {
|
||||
|
||||
ent = tree_next_ent(current);
|
||||
|
||||
if (ent == NULL) {
|
||||
|
||||
if (rm())
|
||||
continue;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
index_entry(ent);
|
||||
#if __DEBUG__
|
||||
printf("DEBUG: indexer_run(): ");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
inline int indexer_pending() {
|
||||
return current != NULL || st_size;
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
#ifndef _INDEXER_H
|
||||
|
||||
#define _INDEXER_H
|
||||
|
||||
void indexer_register(const char *base, const char *name);
|
||||
|
||||
void indexer_run();
|
||||
|
||||
inline int indexer_pending();
|
||||
|
||||
#endif /* _INDEXER_H */
|
||||
|
|
@ -3,7 +3,7 @@ CC=gcc
|
|||
CFLAGS=-g -D__DEBUG__
|
||||
LDFLAGS=-L/usr/lib64/mysql -lmysqlclient
|
||||
|
||||
all : raw_inotify strbuf path rbtree inotify tree indexer mysql stdout queue
|
||||
all : raw_inotify strbuf path rbtree inotify tree mysql stdout queue
|
||||
|
||||
raw_inotify :
|
||||
$(CC) -linotifytools t_raw_inotify.c -o test_raw_inotify
|
||||
|
|
@ -52,22 +52,6 @@ tree :
|
|||
../src/common/die.c \
|
||||
../src/common/strbuf.c \
|
||||
t_tree.c -o test_tree
|
||||
|
||||
indexer :
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) \
|
||||
../src/common/rbtree.c \
|
||||
../src/common/path.c \
|
||||
../src/common/xalloc.c \
|
||||
../src/common/die.c \
|
||||
../src/common/strbuf.c \
|
||||
../src/notify/tree.c \
|
||||
../src/notify/inotify.c \
|
||||
../src/notify/event.c \
|
||||
../src/ini/iniparser.c \
|
||||
../src/ini/dictionary.c \
|
||||
../src/output/stdout.c \
|
||||
../src/indexer.c \
|
||||
t_indexer.c -o test_indexer
|
||||
|
||||
mysql :
|
||||
$(CC) -D DB_DEBUG $(CFLAGS) $(LDFLAGS) \
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include "../src/indexer.h"
|
||||
|
||||
int main() {
|
||||
|
||||
indexer_register("/home/pnx/", "tmptree");
|
||||
indexer_register("/home/pnx/", "tmptree");
|
||||
indexer_register("/home/pnx/", "tmptree");
|
||||
|
||||
while(indexer_pending()) {
|
||||
indexer_run(5);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
printf("---\n");
|
||||
|
||||
indexer_register("/home/pnx/", "tmptree");
|
||||
|
||||
while(indexer_pending()) {
|
||||
indexer_run(5);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
printf("done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in a new issue