From e609fe8e4e7fca623a939cb6ecf73979a8666a45 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 4 Sep 2022 11:41:16 -0500 Subject: try a different approach --- src/slskd/Shares/SharedFileCache.cs | 50 +++++-------------------------------- src/slskd/Shares/Types/File.cs | 33 ------------------------ 2 files changed, 6 insertions(+), 77 deletions(-) delete mode 100644 src/slskd/Shares/Types/File.cs (limited to 'src') diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs index 666fd16c..3a41f61b 100644 --- a/src/slskd/Shares/SharedFileCache.cs +++ b/src/slskd/Shares/SharedFileCache.cs @@ -279,41 +279,20 @@ namespace slskd.Shares // merge the new dictionary with the rest this will overwrite any duplicate keys, but keys are the fully // qualified name the only time this *should* cause problems is if one of the shares is a subdirectory of another. - foreach (var record in newFiles) + foreach (var file in newFiles) { - var (key, value) = record; - - if (filters.Any(filter => filter.IsMatch(key))) + if (filters.Any(filter => filter.IsMatch(file.Key))) { filteredFiles++; continue; } - if (files.ContainsKey(key)) - { - Log.Warning($"File {key} shared in directory {directory} has already been cached. This is probably a misconfiguration of the shared directories (is a subdirectory being re-shared?)."); - } - - // if we're on an operating system that uses forward slashes, it is possible for filenames to contain - // backslashes. because we normalize directory separators to backslashes before we send results to the network, - // we need to replace any backslashes with a placeholder to prevent things from breaking. we'll capture the original - // filename if we do this so we can resolve the original filename given the replacement without doing any guessing. - if (Path.DirectorySeparatorChar == '/' && value.Filename.Contains('\\')) + if (files.ContainsKey(file.Key)) { - Log.Warning($"Substituting {value.Filename} with {value.Filename.Replace('\\', '_')}"); - - // todo: store OriginalFilename for all files once masked filenames are stored in the db. we aren't doing this now to reduce memory footprint. - key = key.Replace('\\', '_'); - value = new File( - value.Code, - value.Filename.Replace('\\', '_'), - value.Size, - value.Extension, - value.Attributes, - originalFilename: value.Filename); + Log.Warning($"File {file.Key} shared in directory {directory} has already been cached. This is probably a misconfiguration of the shared directories (is a subdirectory being re-shared?)."); } - files[key] = value; + files[file.Key] = file.Value; } } catch (Exception ex) @@ -415,29 +394,12 @@ namespace slskd.Shares /// The unmasked filename. public string Resolve(string filename) { - Log.Warning($"Resolving: {filename}"); - // ensure this is a tracked file - if (!MaskedFiles.TryGetValue(filename, out var maskedRecord)) + if (!MaskedFiles.TryGetValue(filename, out _)) { - Log.Warning("Not tracked"); return null; } - // if the OriginalFilename property of the record was set during the scan, - // one or more characters was substituted, and we can't trust the manipulated - // path to find the correct file without some degree of guessing. return the - // value of OriginalFilename which definitively points to the location on disk. - if (!string.IsNullOrEmpty(maskedRecord.OriginalFilename)) - { - Log.Warning($"OriginalFilename populated: {maskedRecord.OriginalFilename}"); - // todo: use OriginalFilename for all files once masked files are stored in the db - filename = maskedRecord.OriginalFilename; - } - - // if OriginalFilename isn't set, derive the location of the file from the masked - // filename and share configuration. we don't store OriginalFilename for all records - // to reduce memory footprint var resolved = filename; // a well-formed path will consist of a mask, either an alias or a local directory, and a fully qualified path to a diff --git a/src/slskd/Shares/Types/File.cs b/src/slskd/Shares/Types/File.cs deleted file mode 100644 index e7740613..00000000 --- a/src/slskd/Shares/Types/File.cs +++ /dev/null @@ -1,33 +0,0 @@ -// -// Copyright (c) slskd Team. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see https://www.gnu.org/licenses/. -// - -namespace slskd.Shares -{ - using System.Collections.Generic; - using Soulseek; - - public class File : Soulseek.File - { - public File(int code, string filename, long size, string extension, IEnumerable attributeList = null, string originalFilename = null) - : base(code, filename, size, extension, attributeList) - { - OriginalFilename = originalFilename; - } - - public string OriginalFilename { get; set; } - } -} -- cgit v1.2.3