From f9ace7b7d95cd555832079e0dd53cf78eecf3262 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 8 Dec 2022 14:16:35 +0000 Subject: [PATCH] [UnitTests] Add code to generate extended attributes list and MD5s when building contents JSON for ReadOnlyFilesystemTest. --- .../Filesystems/ReadOnlyFilesystemTest.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Aaru.Tests/Filesystems/ReadOnlyFilesystemTest.cs b/Aaru.Tests/Filesystems/ReadOnlyFilesystemTest.cs index e0de5697c..86071cf01 100644 --- a/Aaru.Tests/Filesystems/ReadOnlyFilesystemTest.cs +++ b/Aaru.Tests/Filesystems/ReadOnlyFilesystemTest.cs @@ -296,6 +296,10 @@ public abstract class ReadOnlyFilesystemTest : FilesystemTest else data.Md5 = BuildFile(fs, childPath, stat.Length); + if(fs.ListXAttr(childPath, out List xattrs) == ErrorNumber.NoError && + xattrs.Count > 0) + data.XattrsWithMd5 = BuildFileXattrs(fs, childPath); + children[child] = data; } @@ -310,6 +314,30 @@ public abstract class ReadOnlyFilesystemTest : FilesystemTest return Md5Context.Data(buffer, out _); } + static Dictionary BuildFileXattrs(IReadOnlyFilesystem fs, string path) + { + fs.ListXAttr(path, out List contents); + + if(contents.Count == 0) + return null; + + Dictionary xattrs = new(); + + foreach(string xattr in contents) + { + byte[] buffer = Array.Empty(); + ErrorNumber ret = fs.GetXattr(path, xattr, ref buffer); + string data; + + data = ret != ErrorNumber.NoError ? Md5Context.Data(Array.Empty(), out _) + : Md5Context.Data(buffer, out _); + + xattrs[xattr] = data; + } + + return xattrs; + } + internal static void TestDirectory(IReadOnlyFilesystem fs, string path, Dictionary children, string testFile, bool testXattr, out List nextLevels, int currentDepth)