Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updatePaths work without being supplied new_dir and new_path #1034

Merged
merged 4 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions sarracenia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,11 +769,23 @@ def updatePaths(msg, options, new_dir=None, new_file=None):
])
if new_dir:
msg['new_dir'] = new_dir
elif 'new_dir' in msg:
new_dir = msg['new_dir']
else:
new_dir = ''

if new_file or new_file == '':
msg['new_file'] = new_file

relPath = new_dir + '/' + new_file
elif 'new_file' in msg:
new_file = msg['new_file']
elif 'new_relPath' in msg:
new_file = os.path.basename(msg['rel_relPath'])
elif 'relPath' in msg:
new_file = os.path.basename(msg['relPath'])
else:
new_file = 'ErrorInSarraceniaMessageUpdatePaths.txt'

newFullPath = new_dir + '/' + new_file

# post_baseUrl option set in msg overrides other possible options
if 'post_baseUrl' in msg:
Expand Down Expand Up @@ -802,23 +814,23 @@ def updatePaths(msg, options, new_dir=None, new_file=None):
pbd_str = options.variableExpansion(options.post_baseDir, msg)
parsed_baseUrl = sarracenia.baseUrlParse(baseUrl_str)

if relPath.startswith(pbd_str):
relPath = new_dir.replace(pbd_str, '', 1) + '/' + new_file
if newFullPath.startswith(pbd_str):
newFullPath = new_dir.replace(pbd_str, '', 1) + '/' + new_file

if (len(parsed_baseUrl.path) > 1) and relPath.startswith(
if (len(parsed_baseUrl.path) > 1) and newFullPath.startswith(
parsed_baseUrl.path):
relPath = relPath.replace(parsed_baseUrl.path, '', 1)
newFullPath = newFullPath.replace(parsed_baseUrl.path, '', 1)

if ('new_dir' not in msg) and options.post_baseDir:
msg['new_dir'] = options.post_baseDir

msg['new_baseUrl'] = baseUrl_str

if len(relPath) > 0 and relPath[0] == '/':
relPath = relPath[1:]
if len(newFullPath) > 0 and newFullPath[0] == '/':
newFullPath = newFullPath[1:]

msg['new_relPath'] = relPath
msg['new_subtopic'] = relPath.split('/')[0:-1]
msg['new_relPath'] = newFullPath
msg['new_subtopic'] = newFullPath.split('/')[0:-1]

for i in ['relPath', 'subtopic', 'baseUrl']:
if not i in msg:
Expand Down
6 changes: 5 additions & 1 deletion sarracenia/flow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,11 @@ def download(self, msg, options) -> bool:
if self.o.dry_run:
cwd = cdir
else:
self.proto[self.scheme].cd(cdir)
try:
self.proto[self.scheme].cd(cdir)
except Exception as ex:
logger.error("chdir %s: %s" % (cdir, ex))
return False

remote_offset = 0
exactLength=False
Expand Down
5 changes: 1 addition & 4 deletions sarracenia/sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2659,10 +2659,7 @@ def convert(self):
v3_cfg.write('# topicCopy on is only there for bug-for-bug compat with v2. turn it off if you can.\n')
v3_cfg.write('#topicCopy on\n')

if component in [ 'sarra', 'subscribe' ]:
v3_cfg.write('#v2 sftp handling is always absolute, sr3 is relative. This plugin helps during conversion, remove when all sr3:\n')
v3_cfg.write('flowcb accept.sftp_absolute\n')
if component in [ 'sender' ]:
if component in [ 'sarra', 'sender', 'subscribe' ]:
v3_cfg.write('#v2 sftp handling is always absolute, sr3 is relative. might need this, remove when all sr3:\n')
v3_cfg.write('#flowcb accept.sftp_absolute\n')

Expand Down
3 changes: 2 additions & 1 deletion sarracenia/transfer/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ def registered_as():

# cd
def cd(self, path):
logger.debug("sr_sftp cd %s" % path)
alarm_set(self.o.timeout)
logger.debug("first cd to %s" % self.originalDir)
self.sftp.chdir(self.originalDir)
logger.debug("then cd to %s" % path)
self.sftp.chdir(path)
self.pwd = path
alarm_cancel()
Expand Down
Loading