Ejemplo n.º 1
0
def test_non_utf(conn, tmp_path):
    a = str(tmp_path / '\ud83d').encode('utf-8', 'surrogatepass')
    os.mkdir(a)

    scan(tmp_path, conn)

    q = sa.select([sa.func.count()]).select_from(model.paths)
    r = conn.execute(q).scalar()
    assert r == count_files(tmp_path)
Ejemplo n.º 2
0
def test_scan_twice(conn, sample_db, sample_data):
    # Scanning the same directory twice should not change data
    q = sa.select([model.paths.c.id])
    r = conn.execute(q)
    assert len(list(r)) == count_files(sample_data)

    scan(sample_data, conn)

    q = sa.select([model.paths.c.id])
    r = conn.execute(q)
    assert len(list(r)) == count_files(sample_data)
Ejemplo n.º 3
0
def test_scan_empty(conn, tmp_path):
    a = tmp_path / 'a'
    a.mkdir()
    scan(a, conn)

    q = sa.select([sa.func.count()]).select_from(model.paths)
    r = conn.execute(q).scalar()
    assert r == 1

    q = sa.select([model.paths])
    r = list(conn.execute(q))
    assert r[0].parent_id == None
    assert r[0].last_seen != None
    assert r[0].parent_inode != None
    assert r[0].parent_device != None
Ejemplo n.º 4
0
def test_directory_group_readable(conn, tmp_path):
    a = tmp_path / 'a'
    a.mkdir()

    # Directory is group readable
    a.chmod(0o740)
    scan(tmp_path, conn)
    root_id = get_path_id(tmp_path, conn)
    r = DirectoryGroupReadable().query([root_id])
    assert len(list(conn.execute(r))) == 0

    # Directory is not group readable
    a.chmod(0o700)
    scan(tmp_path, conn)
    r = DirectoryGroupReadable().query([root_id])
    assert len(list(conn.execute(r))) == 1
Ejemplo n.º 5
0
def test_scan_inheritance(conn, tmp_path):
    a = tmp_path / 'a'
    a.mkdir()
    scan(a, conn)

    b = a / 'b'
    b.mkdir()
    scan(a, conn)

    q = sa.select([sa.func.count()]).select_from(model.paths)
    r = conn.execute(q).scalar()
    assert r == 2

    q = sa.select([model.paths]).order_by(model.paths.c.id)
    r = list(conn.execute(q))
    assert r[1].parent_inode == r[0].inode
    assert r[1].parent_device == r[0].device
    assert r[1].parent_id == r[0].id
    assert r[1].last_seen != None
Ejemplo n.º 6
0
def test_update(conn, tmp_path):
    a = tmp_path / 'a'
    b = a / 'b'
    for p in [a, b]:
        p.mkdir()
    c = b / 'c'
    c.write_text('hello')
    scan(tmp_path, conn)
    q = sa.select([model.paths.c.size
                   ]).where(model.paths.c.inode == c.stat().st_ino)
    r = conn.execute(q).scalar()
    assert r == c.stat().st_size

    c.write_text(' world!')
    scan(tmp_path, conn)
    q = sa.select([model.paths.c.size
                   ]).where(model.paths.c.inode == c.stat().st_ino)
    r = conn.execute(q).scalar()
    assert r == c.stat().st_size
Ejemplo n.º 7
0
def test_delete(conn, tmp_path):
    a = tmp_path / 'a'
    b = a / 'b'
    c = a / 'c'
    d = a / 'd'
    for p in [a, b, c, d]:
        p.mkdir()
    scan(tmp_path, conn)
    q = sa.select([sa.func.count()]).select_from(model.paths)
    r = conn.execute(q).scalar()
    assert r == count_files(tmp_path)

    # Remove a file and scan it
    b.rmdir()
    scan(tmp_path, conn)
    q = sa.select([sa.func.count()]).select_from(model.paths)
    r = conn.execute(q).scalar()
    assert r == count_files(tmp_path)

    # Remove a file and don't scan it - doesn't update DB
    d.rmdir()
    scan(c, conn)
    q = sa.select([sa.func.count()]).select_from(model.paths)
    r = conn.execute(q).scalar()
    assert r != count_files(tmp_path)
Ejemplo n.º 8
0
def test_owned_by(conn, tmp_path):
    a = tmp_path / 'a'
    a.mkdir()

    b = tmp_path / 'b'
    b.mkdir()

    scan(tmp_path, conn)

    conn.execute("""
        UPDATE paths SET uid = -1
        WHERE id IN (
            SELECT paths.id
            FROM paths
            JOIN basenames ON paths.basename_id = basenames.id
            WHERE basenames.name = 'b'
            )
        """)

    root_id = get_path_id(tmp_path, conn)
    r = OwnedBy(user=-1).query([root_id])

    # Two files not owned by -1 (root and 'a')
    assert len(list(conn.execute(r))) == 2
Ejemplo n.º 9
0
def test_scan_mdss(conn):
    from dusqlite.scan import scan
    scan('mdss://w35/saw562', conn)
Ejemplo n.º 10
0
def sample_db(conn, sample_data):
    scan(sample_data, conn)