From 185669ec727d6e644244308758ec8f74413c976f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 17 Nov 2021 11:46:37 +0530 Subject: [PATCH] Use a shorter random id for transfers Reduces overhead and we dont actually need protection against malicious actors, only accidental collisions --- kittens/transfer/utils.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/kittens/transfer/utils.py b/kittens/transfer/utils.py index 627d0b8cf..54ed9589e 100644 --- a/kittens/transfer/utils.py +++ b/kittens/transfer/utils.py @@ -2,13 +2,13 @@ # License: GPLv3 Copyright: 2021, Kovid Goyal import os +import secrets from contextlib import contextmanager from datetime import timedelta from mimetypes import guess_type -from typing import Callable, Generator, Union +from typing import Generator, Union from kitty.fast_data_types import truncate_point_for_length, wcswidth -from kitty.types import run_once from ..tui.operations import styled from ..tui.progress import render_progress_bar @@ -151,14 +151,10 @@ def expand_home(path: str) -> str: return path -@run_once -def short_uuid_func() -> Callable[[], str]: - from kitty.short_uuid import ShortUUID, escape_code_safe_alphabet - return ShortUUID(alphabet=''.join(set(escape_code_safe_alphabet) - {';'})).uuid4 - - def random_id() -> str: - return short_uuid_func()() + ans = hex(os.getpid())[2:] + x = secrets.token_hex(2) + return ans + x @contextmanager