sapling/eden/fs/cli/prjfs.py
Zeyi (Rice) Fan b62f870fe8 cli: add debug state for checking projectedfs file state
Summary: A simple debug command to help check ProjectedFS File State on disk

Reviewed By: chadaustin

Differential Revision: D26918172

fbshipit-source-id: 098724fbb0ca1e8eb6798b3ce669a43e2ea576ee
2021-03-10 10:05:42 -08:00

45 lines
1.2 KiB
Python

#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2.
# TODO(T65013742): Can't type check Windows on Linux
# pyre-ignore-all-errors
import ctypes
import ctypes.wintypes
import enum
from ctypes.wintypes import LPCWSTR
from pathlib import Path
prjfs = ctypes.windll.projectedfslib
class PRJ_FILE_STATE(enum.IntFlag):
Placeholder = 1
HydratedPlaceholder = 2
DirtyPlaceholder = 4
Full = 8
Tombstone = 16
_PrjGetOnDiskFileState = prjfs.PrjGetOnDiskFileState
_PrjGetOnDiskFileState.restype = ctypes.HRESULT
_PrjGetOnDiskFileState.argtypes = [
ctypes.wintypes.LPCWSTR,
ctypes.POINTER(ctypes.c_int),
]
def PrjGetOnDiskFileState(path: Path) -> PRJ_FILE_STATE:
state = ctypes.c_int(0)
result = _PrjGetOnDiskFileState(LPCWSTR(str(path)), ctypes.byref(state))
# Python will automatically throw OSError when result is non-zero
if result == 0:
return PRJ_FILE_STATE(state.value)
# It should never reach here, but just to make typechecker happy
raise RuntimeError("Windows Error: " + result)