Skip to content

Commit

Permalink
Merge pull request #1220 from MetPX/issue1218
Browse files Browse the repository at this point in the history
Fix for Issue1218 - Permission problems in directory creations on FTP/SFTP transfers
  • Loading branch information
petersilva authored Sep 11, 2024
2 parents e011c32 + eabe000 commit be6dcb2
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
6 changes: 3 additions & 3 deletions sarracenia/flow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2431,7 +2431,7 @@ def send(self, msg, options):
(self.scheme, new_dir))
if not self.o.dry_run:
try:
self.proto[self.scheme].cd_forced(775, new_dir)
self.proto[self.scheme].cd_forced(new_dir)
except Exception as ex:
logger.error( f"could not chdir to {sendTo} {new_dir}: {ex}" )
return False
Expand Down Expand Up @@ -2644,8 +2644,8 @@ def send(self, msg, options):
if not self.o.dry_run:
try:
self.proto[self.scheme].cd_forced(
775, new_dir + '/' + options.inflight)
self.proto[self.scheme].cd_forced(775, new_dir)
new_dir + '/' + options.inflight)
self.proto[self.scheme].cd_forced(new_dir)
except:
pass
new_inflight_path = options.inflight + new_file
Expand Down
2 changes: 1 addition & 1 deletion sarracenia/transfer/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def cd(self, path):
self.path = self.path.lstrip('/')


def cd_forced(self, perm, path):
def cd_forced(self, path):
logger.debug(f"forcing into {path}")
self.cd(path)

Expand Down
6 changes: 3 additions & 3 deletions sarracenia/transfer/ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def cd(self, path):
finally:
alarm_cancel()

def cd_forced(self, perm, path):
logger.debug("sr_ftp cd_forced %d %s" % (perm, path))
def cd_forced(self, path):
logger.debug("sr_ftp cd_forced %o %s" % (self.o.permDirDefault, path))

# try to go directly to path

Expand Down Expand Up @@ -133,7 +133,7 @@ def cd_forced(self, perm, path):
# chmod
alarm_set(self.o.timeout)
try:
self.ftp.voidcmd('SITE CHMOD ' + "{0:o}".format(perm) + ' ' + d)
self.ftp.voidcmd('SITE CHMOD ' + "{0:o}".format(self.o.permDirDefault) + ' ' + d)
finally:
alarm_cancel()

Expand Down
2 changes: 1 addition & 1 deletion sarracenia/transfer/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def cd(self, path):
self.cwd = os.path.dirname(path)
self.path = path.strip('/') + "/"

def cd_forced(self, perm, path):
def cd_forced(self, path):
logger.debug("sr_s3 cd %s" % path)
self.cwd = os.path.dirname(path)
self.path = path.strip('/') + "/"
Expand Down
13 changes: 8 additions & 5 deletions sarracenia/transfer/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def cd(self, path):
alarm_cancel()

# cd forced
def cd_forced(self, perm, path):
logger.debug("sr_sftp cd_forced %d %s" % (perm, path))
def cd_forced(self, path):
logger.debug("sr_sftp cd_forced %o %s" % (self.o.permDirDefault, path))

# try to go directly to path

Expand Down Expand Up @@ -128,6 +128,8 @@ def cd_forced(self, perm, path):
try:
self.sftp.mkdir(d, self.o.permDirDefault)
self.sftp.chdir(d)
# Apply permDirDefault value. mkdir is limited by SFTP server umask value
self.sftp.chmod('.', self.o.permDirDefault)
finally:
alarm_cancel()

Expand Down Expand Up @@ -455,12 +457,13 @@ def mkdir(self, remote_dir):
pass
except:
return
else:
self.sftp.mkdir(remote_dir, self.o.permDirDefault)
# Apply permDirDefault value. mkdir is limited by SFTP server umask value
self.sftp.chmod(remote_dir, self.o.permDirDefault)
finally:
alarm_cancel()

self.sftp.mkdir(remote_dir, self.o.permDirDefault)
alarm_cancel()

# put
def put(self,
msg,
Expand Down
4 changes: 2 additions & 2 deletions tests/sarracenia/transfer/azure_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_cd_forced():
assert transfer.path == ""
assert transfer.cwd == ""

transfer.cd_forced('777', "/this/Is/A/Path/")
transfer.cd_forced("/this/Is/A/Path/")

assert transfer.path == "this/Is/A/Path/"
assert transfer.cwd == "/this/Is/A/Path"
Expand Down Expand Up @@ -359,4 +359,4 @@ def test_umask():
transfer = sarracenia.transfer.azure.Azure('azure', options)

transfer.umask()
assert True
assert True
4 changes: 2 additions & 2 deletions tests/sarracenia/transfer/s3_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_cd_forced():
assert transfer.path == ""
assert transfer.cwd == ""

transfer.cd_forced('777', "/this/Is/A/Path/")
transfer.cd_forced("/this/Is/A/Path/")

assert transfer.path == "this/Is/A/Path/"
assert transfer.cwd == "/this/Is/A/Path"
Expand Down Expand Up @@ -295,4 +295,4 @@ def test_umask():
transfer = sarracenia.transfer.s3.S3('s3', options)

transfer.umask()
assert True
assert True

0 comments on commit be6dcb2

Please sign in to comment.