Bug report: old permissions on media directories

General discussions.

Moderator: moderators

Bug report: old permissions on media directories

Postby jschuster » Wed Feb 03, 2016 4:50 pm

I ran into an apparent bug where files in directories that used to have overly restrictive permissions would not get picked up in subsequent scans. This was in version 5.3 (build 4568) on Arch Linux. Try this:

1. On a Unix-like system, add a directory under the media directory with permissions set so that the subsonic user does not have read (r) or execute (x) permissions. Put a music file inside that directory.
2. Start a scan of the media directory. The new folder name may appear in the sidebar of the player, but it will not have anything inside
3. Change the new directory's permissions so that subsonic has read and execute permissions.
4. Start a scan again.

Expected result: The music file is now available in subsonic.
Actual result: The music file is still not available. Renaming the folder and rescanning will let it appear.

It appears subsonic is remembering the old permissions and skipping those directories it thinks it can't access during the scan, even when the permissions have been changed. It should probably forget what permissions directories have altogether.
jschuster
 
Posts: 1
Joined: Wed Feb 03, 2016 4:45 pm

Re: Bug report: old permissions on media directories

Postby daneren2005 » Wed Feb 03, 2016 8:20 pm

You just need to make a change to the root folder to get them to show up (at least in my experience that has worked).

@Sindre I have experienced this a bit and it appears that the problem is you do a file change time check in MediaFileService and changing the permissions does not update this time (seems like a flaw in the Filesystem design, but that is irrelevant). When the permissions are bad the method FileUtil.listFiles logs a warning but then marks the folder as present. The simplest solution to this would be to not call `parent.setChildrenLastUpdated(parent.getChanged());` when the method listFiles has a error. This would make it so that it would keep trying to scan the folder until the permissions are fixed which seems like a good thing to me.

A simple example of this fix:

FileUtil:
Code: Select all
    public static File[] listFiles(final File dir) {
        File[] files = timed(new FileTask<File[]>("listFiles", dir) {
            @Override
            public File[] execute() {
                return dir.listFiles();
            }
        });

        if (files == null) {
            LOG.warn("Failed to list children for " + dir.getPath());
            return new File[0];
        }
        return files;
    }

to

Code: Select all
    public static File[] listFiles(final File dir) {
        return listFiles(dir, false);
    }
    public static File[] listFiles(final File dir, boolean allowNull) {
        File[] files = timed(new FileTask<File[]>("listFiles", dir) {
            @Override
            public File[] execute() {
                return dir.listFiles();
            }
        });

        if (files == null) {
            LOG.warn("Failed to list children for " + dir.getPath());
            if(allowNull) {
                return null;
            } else {
                return new File[0];
            }
        }
        return files;
    }


MediaFileService - updateChildren(MediaFile parent):
Code: Select all
        List<File> children = filterMediaFiles(FileUtil.listFiles(parent.getFile()));

to

Code: Select all
        File[] files = FileUtil.listFiles(parent.getFile(), true);
        if(files == null) {
            return;
        }

        List<File> children = filterMediaFiles(files);
Developer of DSub for Android
daneren2005
 
Posts: 1709
Joined: Fri Jul 06, 2012 7:52 pm


Return to General

Who is online

Users browsing this forum: No registered users and 12 guests