Jaya icon indicating copy to clipboard operation
Jaya copied to clipboard

Possible Filesystem disorganization on Linux?

Open Splitwirez opened this issue 4 years ago • 7 comments

So I've finally switched over to Linux, and upon building and running Jaya, I was greeted by this mess:

Screenshot_20200901_124231

...is this the intended result?

Splitwirez avatar Sep 01 '20 16:09 Splitwirez

Seems to me its showing all mount points. This is not at all intended, most likely code needs to be done to just show only removable and fixed media.

waliarubal avatar Sep 01 '20 17:09 waliarubal

Seems to me its showing all mount points. This is not at all intended, most likely code needs to be done to just show only removable and fixed media.

Okay, glad to hear it's at least clear to you what the problem is...I wouldn't have had the slightest clue, lol

Splitwirez avatar Sep 01 '20 18:09 Splitwirez

Decided to experiment with fixing this. In Jaya.Provider.FileSystem/Services/FileSystemService.cs, replacing the GetDirectoryAsync function with the following:

        public override async Task<DirectoryModel> GetDirectoryAsync(AccountModelBase account, DirectoryModel directory = null)
        {
            var model = GetFromCache(account, directory);
            if (model != null)
                return model;

            return await Task.Run(() =>
            {
                model = new DirectoryModel();

                if (string.IsNullOrEmpty(directory.Path))
                {
                    model.Directories = new List<DirectoryModel>();
                    if (ServiceLocator.Instance.GetService<IPlatformService>().GetPlatform() == OSPlatform.Linux)
                    {
                        try
                        {
                            foreach (var driveInfo in DriveInfo.GetDrives())
                            {
                                if (!driveInfo.IsReady)
                                    continue;

                                if (driveInfo.Name.Equals("/", StringComparison.OrdinalIgnoreCase))
                                {
                                    var rootDir = new DirectoryModel();
                                    rootDir.Name = driveInfo.Name;
                                    rootDir.Path = driveInfo.RootDirectory.FullName;
                                    
                                    rootDir = GetDirectoryAsync(account, rootDir).Result;
                                    
                                    model.Directories = rootDir.Directories;
                                    model.Files = rootDir.Files;
                                    break;
                                }
                            }
                        }
                        catch (UnauthorizedAccessException)
                        {

                        }
                    }
                    else
                    {
                        foreach (var driveInfo in DriveInfo.GetDrives())
                        {
                            if (!driveInfo.IsReady)
                                continue;

                            var drive = new DirectoryModel(true);
                            drive.Name = driveInfo.Name;
                            drive.Path = driveInfo.RootDirectory.FullName;
                            drive.Size = driveInfo.TotalSize;
                            model.Directories.Add(drive);
                        }
                    }
                    AddToCache(account, model);
                    return model;
                }

                DirectoryInfo info = new DirectoryInfo(directory.Path);
                model.Name = info.Name;
                model.Path = info.FullName;
                model.Created = info.CreationTime;
                model.Modified = info.LastWriteTime;
                model.Accessed = info.LastAccessTime;
                model.IsHidden = info.Attributes.HasFlag(FileAttributes.Hidden);
                model.IsSystem = info.Attributes.HasFlag(FileAttributes.System);

                model.Files = new List<FileModel>();
                try
                {
                    foreach (var fileInfo in info.GetFiles())
                    {
                        var file = new FileModel();
                        if (string.IsNullOrEmpty(fileInfo.Extension))
                            file.Name = fileInfo.Name;
                        else
                        {
                            file.Name = fileInfo.Name.Replace(fileInfo.Extension, string.Empty);
                            file.Extension = fileInfo.Extension.Substring(1).ToLowerInvariant();
                        }
                        file.Path = fileInfo.FullName;
                        file.Size = fileInfo.Length;
                        file.Created = fileInfo.CreationTime;
                        file.Modified = fileInfo.LastWriteTime;
                        file.Accessed = fileInfo.LastAccessTime;
                        file.IsHidden = fileInfo.Attributes.HasFlag(FileAttributes.Hidden);
                        file.IsSystem = fileInfo.Attributes.HasFlag(FileAttributes.System);
                        model.Files.Add(file);
                    }
                }
                catch (UnauthorizedAccessException)
                {

                }

                model.Directories = new List<DirectoryModel>();
                try
                {
                    foreach (var directoryInfo in info.GetDirectories())
                    {
                        var dir = new DirectoryModel();
                        dir.Name = directoryInfo.Name;
                        dir.Path = directoryInfo.FullName;
                        dir.Created = directoryInfo.CreationTime;
                        dir.Modified = directoryInfo.LastWriteTime;
                        dir.Accessed = directoryInfo.LastAccessTime;
                        dir.IsHidden = directoryInfo.Attributes.HasFlag(FileAttributes.Hidden);
                        dir.IsSystem = directoryInfo.Attributes.HasFlag(FileAttributes.System);
                        model.Directories.Add(dir);
                    }
                }
                catch (UnauthorizedAccessException)
                {

                }

                AddToCache(account, model);
                return model;
            });
        }

Seems to produce more desirable results. Is this an acceptable solution?

Splitwirez avatar Sep 03 '20 19:09 Splitwirez

It should be acceptable if you have tested it with Windows and Mac. If this piece works there without any issues then it should be no problem at all.

waliarubal avatar Sep 04 '20 06:09 waliarubal

It should be acceptable if you have tested it with Windows and Mac. If this piece works there without any issues then it should be no problem at all.

Just tested and can verify that it works without a hitch on Windows. Unfortunately, I have no means of testing on macOS...didn't you say you'd picked up an old macbook or something not too long ago?

Splitwirez avatar Sep 04 '20 11:09 Splitwirez

I picked up a new MacMini 2014 model in July. Will test it on that. Please add your code and push it to the repository since you have access.

waliarubal avatar Sep 07 '20 08:09 waliarubal

I picked up a new MacMini 2014 model in July. Will test it on that. Please add your code and push it to the repository since you have access.

Okay, done. Looking forward to those test results.

Splitwirez avatar Sep 07 '20 15:09 Splitwirez

We are rewriting old codebase, this issue is no more relevant.

waliarubal avatar Aug 25 '22 06:08 waliarubal