Skip to content

Commit

Permalink
fix windows file rename
Browse files Browse the repository at this point in the history
  • Loading branch information
baskiton committed May 27, 2024
1 parent d872369 commit 702167a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
16 changes: 14 additions & 2 deletions SatsDecoder/systems/image_receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import math
import pathlib
import shutil
import sys
import threading


Expand Down Expand Up @@ -52,8 +54,18 @@ def rename(self, new_filename):
try:
self.fn.rename(new_filename)
break
except PermissionError as e:
if not (sys.platform == 'win32' and e.winerror == 32):
raise
shutil.copyfile(old, new_filename)
break
except FileExistsError:
new_filename.unlink(True)
try:
new_filename.unlink()
except IsADirectoryError:
new_filename.rmdir()
except FileNotFoundError:
pass
self.fn = new_filename
self.renamed = old

Expand Down Expand Up @@ -111,7 +123,7 @@ def __init__(self, outdir, suff=None):
self.outdir.mkdir(parents=True, exist_ok=True)
self.images = {}
self.merge_mode = 0
self.current_fid = None
self.current_fid = ''
self.last_date = 0

@property
Expand Down
8 changes: 5 additions & 3 deletions SatsDecoder/systems/usp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,11 +1480,13 @@ class UspImageReceiver(ImageReceiver):
def __init__(self, outdir):
super().__init__(outdir)

def generate_fid(self, fname='unknown'):
if self.current_fid == 'unknown':
def generate_fid(self, fname=''):
if self.current_fid.startswith('unknown_') and fname:
self.rename_image(self.current_fid, fname)
elif not (self.current_fid and self.merge_mode):
self.last_date = dt.datetime.now()
self.last_date = now = dt.datetime.now()
if not fname:
fname = f'unknown_{now.strftime("%Y-%m-%d_%H-%M-%S,%f")}'
self.current_fid = fname
return self.current_fid

Expand Down

0 comments on commit 702167a

Please sign in to comment.