Skip to content

remove copilot changes - #99

Merged
zaihuaji merged 1 commit into
mainfrom
hua-work-common
Apr 23, 2026
Merged

zaihuaji merged 1 commit into
mainfrom
hua-work-common

Conversation

@zaihuaji

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings April 23, 2026 20:24
@zaihuaji
zaihuaji merged commit d0446cb into main Apr 23, 2026
3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates PgFile’s file/dir utility layer, including backup/remote/object handling and a large set of new helper methods (backup/tar/ftp stat parsing, globbing, local access checks, and file conversion).

Changes:

  • Adjusts several existing behaviors/signatures (e.g., object→remote copy signature, remote “missing file” detection, compression-extension matching).
  • Adds/expands backup/tar/ftp stat parsing and multi-host “glob” listing helpers.
  • Adds local access-check helpers and utilities for converting/comparing files and path normalization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -821,7 +821,7 @@ def remote_copy_object(self, tofile, fromfile, host, bucket = None, meta = None,
# host - remote host name
# bucket - bucket name on Object store
# meta - reference to metadata hash

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment block above object_copy_remote() still documents a meta argument, but the function signature no longer accepts meta and the docstring doesn’t mention it. Please update/remove the stale parameter documentation to avoid confusing callers.

Suggested change
# meta - reference to metadata hash

Copilot uses AI. Check for mistakes.
Comment on lines +2477 to +2483
for loop in range(2):
buf = self.pgsystem("tar -tvf {} {}".format(tfile, file), self.LOGWRN, self.CMDRET)
if buf or not self.PGLOG['SYSERR'] or self.PGLOG['SYSERR'].find('Not found in archive') > -1: break
errmsg = self.PGLOG['SYSERR']
(hstat, msg) = self.host_down_status(tfile, self.LHOST, 0, logact)
self.errlog(errmsg, 'L', loop, logact)
if loop > 0: return self.FAILURE

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_tar_file(): returning self.FAILURE whenever loop > 0 means a successful second attempt (loop==1) will still be treated as failure. Return FAILURE only when both attempts fail (e.g., track success/buf explicitly).

Suggested change
for loop in range(2):
buf = self.pgsystem("tar -tvf {} {}".format(tfile, file), self.LOGWRN, self.CMDRET)
if buf or not self.PGLOG['SYSERR'] or self.PGLOG['SYSERR'].find('Not found in archive') > -1: break
errmsg = self.PGLOG['SYSERR']
(hstat, msg) = self.host_down_status(tfile, self.LHOST, 0, logact)
self.errlog(errmsg, 'L', loop, logact)
if loop > 0: return self.FAILURE
buf = None
failed = False
for loop in range(2):
buf = self.pgsystem("tar -tvf {} {}".format(tfile, file), self.LOGWRN, self.CMDRET)
if buf or not self.PGLOG['SYSERR'] or self.PGLOG['SYSERR'].find('Not found in archive') > -1:
failed = False
break
failed = True
errmsg = self.PGLOG['SYSERR']
(hstat, msg) = self.host_down_status(tfile, self.LHOST, 0, logact)
self.errlog(errmsg, 'L', loop, logact)
if failed: return self.FAILURE

Copilot uses AI. Check for mistakes.
Comment on lines 2384 to 2388
bfile = op.basename(file)
bcmd = self.BACKCMD
cmd = f"{bcmd} ls -ep {endpoint} -p {bdir} --filter {bfile}"
loop = 0
flist = {}
ccnt = loop = 0
while loop < 2:

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR title suggests removing changes, but this diff introduces a large set of new helpers (backup/tar/ftp/glob, conversion utilities). Please confirm the PR intent and adjust the title/scope accordingly.

Copilot uses AI. Check for mistakes.
continue
pdir = op.dirname(dir)
if pdir and not re.match(r'^(\.|\./|/)$', pdir): dirs[pdir] = host
pdir = self.dirname(dir)

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean_delete_directory() calls self.dirname(dir), but PgFile (and its parents) don’t define a dirname() method (only os.path.dirname is used elsewhere). This will raise AttributeError at runtime; use op.dirname(dir) (or an existing helper) instead.

Suggested change
pdir = self.dirname(dir)
pdir = op.dirname(dir)

Copilot uses AI. Check for mistakes.

# remove the empty given directory and its all subdirectories
# return 1 if empty directory removed 0 otherwise
# return 1 if empty dirctory removed 0 otherwise

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: “dirctory” → “directory”.

Suggested change
# return 1 if empty dirctory removed 0 otherwise
# return 1 if empty directory removed 0 otherwise

Copilot uses AI. Check for mistakes.
tuple: (output_filename, updated_fmt) after the operation.
"""
ms = re.match(r'^(.+)\.{}$'.format(self.CMPSTR), ifile)
ms = re.match(r'^(.+)\.({})'.format(self.CMPSTR), ifile)

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compress_local_file(): the regex used to strip the compression extension is missing an end-of-string anchor, so it can match partial extensions (e.g., 'file.gz.bak') and strip too much. It should only match when the filename ends with one of CMPSTR extensions.

Suggested change
ms = re.match(r'^(.+)\.({})'.format(self.CMPSTR), ifile)
ms = re.match(r'^(.+)\.({})$'.format(self.CMPSTR), ifile)

Copilot uses AI. Check for mistakes.
Comment on lines +2560 to +2566
for loop in range(2):
buf = self.pgsystem(cmd + file, self.LOGWRN, self.CMDRET)
if buf: break
if self.PGLOG['SYSERR']:
self.errlog(self.PGLOG['SYSERR'], 'O', loop, logact|self.LOGERR)
if loop == 0: file = op.dirname(file) + '/'
if loop > 1: return self.FAILURE

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_ftp_file(): if loop > 1: return self.FAILURE can never trigger because loop only ranges over 0..1. Two failed attempts will fall through and return None, losing the error condition; return self.FAILURE when both tries fail and SYSERR indicates an error.

Suggested change
for loop in range(2):
buf = self.pgsystem(cmd + file, self.LOGWRN, self.CMDRET)
if buf: break
if self.PGLOG['SYSERR']:
self.errlog(self.PGLOG['SYSERR'], 'O', loop, logact|self.LOGERR)
if loop == 0: file = op.dirname(file) + '/'
if loop > 1: return self.FAILURE
buf = None
for loop in range(2):
buf = self.pgsystem(cmd + file, self.LOGWRN, self.CMDRET)
if buf: break
if self.PGLOG['SYSERR']:
self.errlog(self.PGLOG['SYSERR'], 'O', loop, logact|self.LOGERR)
if loop == 0: file = op.dirname(file) + '/'
if not buf:
return self.FAILURE if self.PGLOG['SYSERR'] else None

Copilot uses AI. Check for mistakes.
Comment on lines +3363 to +3365
if actstr: actstr += '-'
self.errlog("{}{}: Accessible, but Unexecutable on'{}'".format(actstr, path, self.PGLOG['HOSTNAME']), 'L', 1, logact)
return self.FAILURE

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new local-access helper error strings have formatting/wording issues (e.g., missing space before hostname in "on'{}'" and "Unaccessible" wording). Please adjust these messages for readability/consistency with other errlog outputs.

Copilot uses AI. Check for mistakes.
for i in range(cnt):
afile = files[i]
if op.isabs(afile):
files[i] = self.join_paths(afile, cdir, 1)

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_relative_paths(): join_paths(path1, path2, diff=1) removes path1 from path2. The current call uses (afile, cdir, 1), which will compute the wrong relative path. Swap the arguments to remove cdir from afile.

Suggested change
files[i] = self.join_paths(afile, cdir, 1)
files[i] = self.join_paths(cdir, afile, 1)

Copilot uses AI. Check for mistakes.
# bucket - bucket name on Object store
# meta - reference to metadata hash
def object_copy_remote(self, tofile, fromfile, host, bucket = None, meta = None, logact = 0):
def object_copy_remote(self, tofile, fromfile, host, bucket = None, logact = 0):

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In object_copy_remote(), the upload to the remote host appears to call local_copy_remote() with fromfile (the object-store key) as the destination path. This likely should use tofile as the remote destination; otherwise the remote copy will be written to an incorrect path/name.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants