# -*- coding: utf-8 -*-
"""只操作本程序创建的临时对象；全部数据为合成样本。"""
import os, sys, json, sqlite3, tempfile, pathlib, subprocess, time, socket, stat
from pathlib import Path
def emit(**kw):
    print(json.dumps(kw, ensure_ascii=False, sort_keys=True))
with tempfile.TemporaryDirectory(prefix='ywebs-next132-b2-unlink-') as d:
    p=Path(d)/'demo.log'; f=open(str(p),'w+b'); f.write(b'x'*65536); f.flush()
    if os.name=='posix':
        os.unlink(str(p)); info=os.fstat(f.fileno()); f.seek(0); data=f.read(3)
        assert not p.exists() and info.st_size==65536 and info.st_nlink==0 and data==b'xxx'
        emit(path_exists=False,open_size=info.st_size,links=info.st_nlink,still_readable=data.decode(),scope='临时文件句柄；未测真实文件系统回收字节')
    else:
        try: os.unlink(str(p)); blocked=False
        except PermissionError: blocked=True
        assert blocked; emit(windows_delete_blocked=blocked,scope='Windows打开文件删除边界，未做Unix实验')
    f.close()
