Proposed fix for NTFS\File.cs BestName property

Mar 5, 2010 at 8:22 PM

I rewrote BestName (proposed impl below).  This version ensures that only names that are valid for the file path that opened the file are parsed.  With numours hardlinks the original version could return incorrect data since all names were searched, not just those in the context of the file. 

Bill

        public string BestName
        {
            get
            {
                NtfsAttribute[] attrs = GetAttributes(AttributeType.FileName);

                if (attrs != null && attrs.Length != 0)
                {
                    for (int i = 0; i < attrs.Length; ++i)
                    {
                        // Only look for names in 'this' directory
                        StructuredNtfsAttribute<FileNameRecord> attr = (StructuredNtfsAttribute<FileNameRecord>)attrs[i];
                        if (attr.Content.ParentDirectory.Value != this.DirectoryEntry.Details.ParentDirectory.Value)
                        {
                            continue;
                        }

                        string name = attr.Content.FileName;

                        if (Utilities.Is8Dot3(name) && name.Contains("~"))
                        {
                            continue;
                        }
                       
                        return name;
                    }
                }

                return null;
            }
        }

Coordinator
Mar 6, 2010 at 12:16 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Mar 6, 2010 at 12:17 AM

Thanks Bill,

I'll take a look - for now I've copied this to a work item to track it.

Cheers,

Ken