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

Provide permissions, owner, and group for files on UNIX platforms #48

Closed
giampaolo opened this issue May 28, 2014 · 21 comments
Closed

Provide permissions, owner, and group for files on UNIX platforms #48

giampaolo opened this issue May 28, 2014 · 21 comments
Assignees
Labels
Component-Library enhancement imported imported from old googlecode site and very likely outdated

Comments

@giampaolo
Copy link
Owner

From jlo...@gmail.com on October 30, 2007 14:47:58

Currently, pyftpdlib does not fetch real permissions, owner and group for
files and folders, instead using default fake values. Since the permissions
and owner/group are not applicable in the same fashion on Windows, such
information is currently UNIX only.

The format_list() method of AbstractedFS should be modified to fetch the
owner/group names for each file and the permissions for owner/group/world
to match the standard "ls" output on UNIX platforms. Platforms where the
necessary modules do not exist should fall back on the default values we
use currently.

Original issue: http://code.google.com/p/pyftpdlib/issues/detail?id=48

@giampaolo giampaolo self-assigned this May 28, 2014
@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on October 30, 2007 06:49:45

Checked in a preliminary version of this into my branch in SVN and created a testbed
script called ls.py to play with this. Tested briefly on Linux and OS X platforms.
Will review and test on Windows platform also and check into main branch once
everything looks good.

Attachment: ls.py

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on October 30, 2007 14:37:48

- rename "stat" variable to "stat_result"
- replace stat[int] with stat.value
- add number of links to inode as well instead of just using '1'

Attachment: ls.py

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on October 30, 2007 15:19:56

Turns out tarfile.filemode() returns sane values for Windows too so we don't need to
set default values for Win platforms. removed unneeded code and use UID/GID for
Windows platforms where pwd/grp modules are not available

Attachment: ls.py

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on October 30, 2007 15:51:06

Fixed typo, remove UID/GID and returned to default values since Windows always
returns 0 for those stat values. Added 10 space padding to the file size again to
restore some type of formatting also.

Still need to iron out a better way to do the formatting like ls does it but
otherwise should be most of the way there.

Attachment: ls.py

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on October 30, 2007 18:59:19

- Moved tarfile, pwd and grp module imports outside format_list function.
- (posix) Used specific KeyError exception for catching pwd.getpwuid() and
grp.getgrgid() exceptions.
- (posix) If can't get user and group names use raw uid/gid instead.
- Where posix security model is nonsense use bogus "owner" and "group" values instead.
- (non-posix) Have nlinks = '1' if can't have a reliable number of links to the inode.
- Removed dir_perms variable which was useless.
- Added other space paddings to restore the output formatting as it was before as
long as we don't get a better way to emulate ls formatting.
- Can now use an optional cmd line argument to specify the directory to list.

Labels: Milestone-0.x.x

Attachment: ls.py

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on October 30, 2007 22:33:39

Updated version incorporates some of the changes billiejoex submitted, but also adds
support for formatting the output in the same manner as ls. We will need to discuss
if the overhead is worth bothering with this and do some benchmarking on Linux,
Windows, and OS X systems to see what the actual performance is in real-life testing.

This version uses a similar method to the coreutils ls C code, storing meta
information about a directory listing in a class and then creating the output using
the meta info.

Attachment: ls.py

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on November 01, 2007 09:33:27

A new problem came out. Please take a look at Issue 49 .

Labels: -Milestone-0.x.x

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on November 01, 2007 11:41:33

Returned to fixed formatting after discussion, also fixed Issue 49 and a few other
bugs relating to the arguments passed to ls.py

Attachment: ls-fixed.py

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on November 01, 2007 12:37:00

- updated comments and docstrings
- removed unnecessary str() call 
- re-ordered code blocks for formatting order

Attachment: ls-fixed.py

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on November 01, 2007 12:44:07

- added parens around except parameters

Attachment: ls-fixed.py

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on November 01, 2007 12:50:57

- comment / docstring width to 79 chars
- added note about permissions on Windows platforms

Attachment: ls-fixed.py

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on November 01, 2007 19:11:22

- used os.readlink(file) instead of os.path.basename(os.path.realpath(file)) to get
the real path to which the symbolic link points.

As far as I can tell, it should be definitively ok for inclusion now.

Attachment: ls-fixed.py

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on November 02, 2007 10:27:19

Implemented in SVN revision 159

Status: Finished

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on November 04, 2007 18:28:22

Labels: Milestone-0.2.1

@giampaolo
Copy link
Owner Author

From yanra...@gmail.com on November 29, 2007 10:54:41

format_list doesn't format symlinks correctly.


The current implementation of format_list in AbstractedFS class always follows 
symlinks.
This should NEVER be done. The linux ls command never does that.

For that reason os.lstat should be used instead of os.stat.

Using os.stat, the l flag in filemode rights is never displayed.
The link name will never be resolved as well [lines 1059-1060].

The solution is to replace [lines 1020-1023]:
            try:
                stat_result = os.stat(file)
            except (OSError,AttributeError):
                stat_result = os.lstat(file)

with a simple:
            stat_result = os.lstat(file)

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on November 29, 2007 13:51:46

Agreed.
My only concern is if it is available on all platforms.
As far as I know where symlinks are not supported os.lstat should be an alias for
os.stat but I'm not 100% sure.

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on November 29, 2007 17:45:15

I decided to use hasattr() to make sure that os.lstat is available,
otherwise os.stat() will be used in replacement.
I also noticed that some module in the stdlib do the same.
This shouldn't be really necessary but, who knows...?
...As we say here in Italy: "'sure' is dead". ;)

Change applied in revision #179 .

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on January 06, 2008 06:36:32

Labels: -Milestone-0.2.1 Milestone-0.3.0

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on January 17, 2008 10:07:33

Fixed in version 0.3.0.

Status: Fixed

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on May 02, 2008 11:26:20

Labels: Version-0.2.0

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on October 13, 2008 12:13:14

Labels: Component-Library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component-Library enhancement imported imported from old googlecode site and very likely outdated
Projects
None yet
Development

No branches or pull requests

1 participant