Commit 57ba0a2a by btimby

A bit of cleanup, and default to using the underlying file mode.

parent 42e2c078
...@@ -143,32 +143,38 @@ class FTPFS(ftpserver.AbstractedFS): ...@@ -143,32 +143,38 @@ class FTPFS(ftpserver.AbstractedFS):
kwargs['st_uid'] = info.get('st_uid', UID) kwargs['st_uid'] = info.get('st_uid', UID)
kwargs['st_gid'] = info.get('st_gid', GID) kwargs['st_gid'] = info.get('st_gid', GID)
if 'st_atime' in info: if 'st_atime' in info:
kwargs['st_atime'] = info.get('st_atime') kwargs['st_atime'] = info['st_atime']
elif 'accessed_time' in info: elif 'accessed_time' in info:
kwargs['st_atime'] = time.mktime(info.get("accessed_time").timetuple()) kwargs['st_atime'] = time.mktime(info["accessed_time"].timetuple())
if 'st_mtime' in info: if 'st_mtime' in info:
kwargs['st_mtime'] = info.get('st_mtime') kwargs['st_mtime'] = info.get('st_mtime')
elif 'modified_time' in info: elif 'modified_time' in info:
kwargs['st_mtime'] = time.mktime(info.get("modified_time").timetuple()) kwargs['st_mtime'] = time.mktime(info["modified_time"].timetuple())
# Pyftpdlib uses st_ctime on Windows platform, try to provide it. # Pyftpdlib uses st_ctime on Windows platform, try to provide it.
if 'st_ctime' in info: if 'st_ctime' in info:
kwargs['st_ctime'] = info.get('st_ctime') kwargs['st_ctime'] = info['st_ctime']
elif 'created_time' in info: elif 'created_time' in info:
kwargs['st_ctime'] = time.mktime(info.get("created_time").timetuple()) kwargs['st_ctime'] = time.mktime(info["created_time"].timetuple())
elif 'st_mtime' in kwargs: elif 'st_mtime' in kwargs:
# As a last resort, just copy the modified time. # As a last resort, just copy the modified time.
kwargs['st_ctime'] = kwargs['st_mtime'] kwargs['st_ctime'] = kwargs['st_mtime']
# Not executable by default, Chrome uses the exec flag to denote directories. # Try to use existing mode.
mode = 0660 if 'st_mode' in info:
# Merge in the type (dir or file). File is tested first, some file systems kwargs['st_mode'] = info['st_mode']
# such as ArchiveMountFS treat archive files as directories too. By checking elif 'mode' in info:
# file first, any such files will be only files (not directories). kwargs['st_mode'] = info['mode']
if self.fs.isfile(path): else:
mode |= stat.S_IFREG # Otherwise, build one. Not executable by default.
elif self.fs.isdir(path): mode = 0660
mode |= stat.S_IFDIR # Merge in the type (dir or file). File is tested first, some file systems
mode |= 0110 # Merge in exec bit # such as ArchiveMountFS treat archive files as directories too. By checking
kwargs['st_mode'] = mode # file first, any such files will be only files (not directories).
if self.fs.isfile(path):
mode |= stat.S_IFREG
elif self.fs.isdir(path):
mode |= stat.S_IFDIR
mode |= 0110 # Merge in exec bit to signal dir is listable
kwargs['st_mode'] = mode
return FakeStat(**kwargs) return FakeStat(**kwargs)
# No link support... # No link support...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment