#!/usr/bin/env python3

import tempfile
import os
import sys

from posix_parity import mergerfs_mount


def main():
    try:
        with mergerfs_mount() as (mount, _):
            (fd, filepath) = tempfile.mkstemp(dir=mount)

            os.unlink(filepath)

            found = False
            for entry in os.scandir(mount):
                if entry.name.startswith(".fuse_hidden"):
                    print("found .fuse_hidden file {}".format(entry.name), end='')
                    found = True

            os.close(fd)

            if found:
                return 1
            return 0
    except RuntimeError as exc:
        print(str(exc), end="")
        return 77


if __name__ == "__main__":
    raise SystemExit(main())
