Example #1
0
        public static async Task <Dictionary <string, string> > GenerateMetadataAsync(string path, System.IO.FileAttributes attributes, Options options, Snapshots.ISnapshotService snapshot)
        {
            try
            {
                Dictionary <string, string> metadata;

                if (!options.SkipMetadata)
                {
                    metadata = snapshot.GetMetadata(path, snapshot.IsSymlink(path, attributes), options.SymlinkPolicy == Options.SymlinkStrategy.Follow);
                    if (metadata == null)
                    {
                        metadata = new Dictionary <string, string>();
                    }

                    if (!metadata.ContainsKey("CoreAttributes"))
                    {
                        metadata["CoreAttributes"] = attributes.ToString();
                    }

                    if (!metadata.ContainsKey("CoreLastWritetime"))
                    {
                        try
                        {
                            metadata["CoreLastWritetime"] = snapshot.GetLastWriteTimeUtc(path).Ticks.ToString();
                        }
                        catch (Exception ex)
                        {
                            Logging.Log.WriteWarningMessage(METALOGTAG, "TimestampReadFailed", ex, "Failed to read timestamp on \"{0}\"", path);
                        }
                    }

                    if (!metadata.ContainsKey("CoreCreatetime"))
                    {
                        try
                        {
                            metadata["CoreCreatetime"] = snapshot.GetCreationTimeUtc(path).Ticks.ToString();
                        }
                        catch (Exception ex)
                        {
                            Logging.Log.WriteWarningMessage(METALOGTAG, "TimestampReadFailed", ex, "Failed to read timestamp on \"{0}\"", path);
                        }
                    }
                }
                else
                {
                    metadata = new Dictionary <string, string>();
                }

                return(metadata);
            }
            catch (Exception ex)
            {
                Logging.Log.WriteWarningMessage(METALOGTAG, "MetadataProcessFailed", ex, "Failed to process metadata for \"{0}\", storing empty metadata", path);
                return(new Dictionary <string, string>());
            }
        }
Example #2
0
        public void GetAttributesFromRootDrives()
        {
            string[] localDrives = System.IO.Directory.GetLogicalDrives();

            foreach (string drive in localDrives)
            {
                try
                {
                    System.IO.FileAttributes netAttributes = System.IO.File.GetAttributes(drive);

                    FileAttributes alphaAttributes = File.GetAttributes(drive);

                    Assert.AreEqual(netAttributes.ToString(), alphaAttributes.ToString());
                }
                catch
                {
                    // do nothing for drives that are not initialized
                }
            }
        }