mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 00:45:18 +03:00
b62f870fe8
Summary: A simple debug command to help check ProjectedFS File State on disk Reviewed By: chadaustin Differential Revision: D26918172 fbshipit-source-id: 098724fbb0ca1e8eb6798b3ce669a43e2ea576ee
45 lines
1.2 KiB
Python
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)
|