Esempio n. 1
0
bool digests::set(const char *id, const char *hash)
{
    assert(id != NULL && hash != NULL);

    void *mp;
    size_t len = strlen(hash);

    private_lock.access();
    unsigned path = NamedObject::keyindex(id, INDEX_KEYSIZE);
    linked_pointer<key> keys = private_paths[path];
    while(is(keys)) {
        if(String::equal(id, keys->id)) {
            if(len == strlen(keys->hash)) {
                String::set(keys->hash, ++len, hash);
                private_lock.commit();
                return true;
            }
            return false;
        }
        keys.next();
    }
    mp = private_cache.alloc(sizeof(key));
    new(mp) key(id, hash);
    private_lock.commit();
    return true;
}
Esempio n. 2
0
void digests::reload(void)
{
    private_lock.modify();
    memset(private_paths, 0, sizeof(private_paths));
    private_cache.purge();
    private_lock.commit();
    load();
}
Esempio n. 3
0
static void add(const char *fpath, const char *prefix = ".")
{
    string_t fn = str(prefix) + "/" + str(fpath);
    char buf[512];
    fsys::fileinfo_t inode;
    int err;
    static unsigned long uniq = 0;

    if(fsys::is_hidden(*fn) && !is(all))
        return;

    err = fsys::info(*fn, &inode);
    if(err) {
        report(fpath, err);
        memset(&inode, 0, sizeof(inode));
    }

    size_t size = strlen(fpath);
    caddr_t mp = (caddr_t)mpager.zalloc(sizeof(entry));
    char *path = mpager.dup(fpath);
    char *id = path;

    const char *fname = strrchr(fpath, '/');
    if(!fname)
        fname = strrchr(fpath, '\\');

    if(fname)
        ++fname;
    else
        fname = path;

    if(is(timesort)) {
        struct tm *dt = localtime(&inode.st_mtime);
        snprintf(buf, sizeof(buf), "%04d%02d%02d %02d%02d%02d%s %08ld",
            dt->tm_year, dt->tm_mon, dt->tm_mday, dt->tm_hour, dt->tm_min, dt->tm_sec, fname, ++uniq);
        id = mpager.dup(buf);
    }

    entry *fp = new(mp) entry(&files, id);
    fp->name = path;
    fp->inode = inode;
    if(fsys::is_dir(&inode))
        ++size;
    if(size > widest)
        widest = size;
}
Esempio n. 4
0
key::key(const char *keyid, const char *keyhash) :
LinkedObject(&private_paths[NamedObject::keyindex(keyid, INDEX_KEYSIZE)])
{
    id = private_cache.dup(keyid);
    hash = private_cache.dup(keyhash);
}
Esempio n. 5
0
static void dump(const char *path)
{
    unsigned count = NamedObject::count(&files, 1);
    unsigned cols = 1, col = 0, rows, row, offset, next;
    const char *months[] = {
        _TEXT("Jan"),
        _TEXT("Feb"),
        _TEXT("Mar"),
        _TEXT("Apr"),
        _TEXT("May"),
        _TEXT("Jun"),
        _TEXT("Jul"),
        _TEXT("Aug"),
        _TEXT("Sep"),
        _TEXT("Oct"),
        _TEXT("Nov"),
        _TEXT("Dec")
    };

    if(!count)
        return;

    if(dumped)
        printf("\n%s:\n", path);

    dumped = true;

    if(widest > (width / 2) - 2)
        cols = 1;
    else
        cols = (width / (widest + 1));

    if(!fsys::is_tty(shell::output()) || is(longform))
        cols = 1;

    NamedObject **index = NamedObject::index(&files, 1);
    index = NamedObject::sort(index, count);
    if((is(reverse) && !is(timesort)) || (is(timesort) && !is(reverse))) {
        unsigned first = 0;
        unsigned last = count - 1;
        while(first < last) {
            swap<NamedObject *>(index[first], index[last]);
            ++first;
            --last;
        }
    }

    rows = ((count + (cols - 1)) / cols);
    for(row = 0; row < rows; ++row) {
        for(col = 0; col < cols; ++col) {
            offset = col * rows + row;
            next = (col + 1) * rows + row;
            if(offset >= count)
                continue;

            entry *node = (entry *)index[offset];
            const char *fn = node->name;
            size_t len = strlen(fn);
            struct tm *dt;

            dt = localtime(&node->inode.st_mtime);

            if(is(longform)) {
                printf("%10ld %s %02d %02d:%02d %s",
                    node->inode.st_size,
                    months[dt->tm_mon], dt->tm_mday,
                    dt->tm_hour, dt->tm_min, fn);
            }
            else
                printf("%s", fn);

            if(fsys::is_dir(&node->inode)) {
                fputc('/', stdout);
                ++len;
            }

            while(next < count && len++ < widest + 1)
                fputc(' ', stdout);
        }
        fputc('\n', stdout);
    }

    delete[] index;
    mpager.purge();
    widest = 0;
    files = NULL;
}