Пример #1
0
        public void TestRaiFileEnsure()
        {   // this test does not really challange the delay caused by massive parallel change operations in Dropbox
            var f0 = new RaiFile($"{TestDir}/Data/EnsureTests/kill.txt");

            f0.mkdir();
            var f = new TextFile($"{TestDir}/Data/EnsureTests/kill.txt");

            for (int i = 0; i < 10000; i++)
            {
                f.Append("Test line " + i.ToString());
            }
            f.Save();
            var f2      = new RaiFile($"{TestDir}/Data/EnsureTests/kill2.txt");
            var start   = DateTimeOffset.UtcNow;
            var result1 = f2.cp(f);

            Assert.True(File.Exists(f2.FullName), "File is supposed to have materialized by now.");
            var cpDuration = DateTimeOffset.UtcNow - start;
            var f3         = new TmpFile();
            var result2    = f3.mv(f2);

            Assert.True(File.Exists(f3.FullName), "File is supposed to have materialized by now.");
            Assert.False(File.Exists(f2.FullName), "File is supposed to have vanished by now.");
            Assert.Equal(0, result1 + result2);
        }
Пример #2
0
        public int Convert(string options, string from, string to)
        {
            message = "";
            int  exitCode = 0;
            bool zip      = to.EndsWith(".zip");

            if (zip)
            {
                to = to.Substring(0, to.Length - 4);
            }
            callString = ImPath + ConvertCommand + " " + options + " " + Os.escapeParam(from) + " " + Os.escapeParam(to);
            call       = new RaiSystem(callString);
            call.Exec(out message);
            exitCode = call.ExitCode;
            if (exitCode != 0 && message.Contains("Permission denied"))
            {
                try
                {
                    FileInfo          fiIntern        = new FileInfo(Os.winInternal(from));
                    FileSecurity      fsec            = fiIntern.GetAccessControl();
                    IdentityReference currentIdentity = new NTAccount(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
                    fsec.SetOwner(currentIdentity);
                    FileSystemAccessRule permissions = new FileSystemAccessRule(currentIdentity, FileSystemRights.ReadAndExecute, AccessControlType.Allow);
                    fsec.AddAccessRule(permissions);
                    fiIntern.SetAccessControl(fsec);
                    // try it again
                    call.Exec(out message);
                    exitCode = call.ExitCode;
                }
                catch (Exception)
                {
                }
            }
            if (zip)
            {
                var inFolder = new RaiFile(to);
                inFolder.Path = inFolder.Path + inFolder.Name;
                inFolder.mkdir();
                inFolder.mv(new RaiFile(to));
                File.Delete(inFolder.FullName + ".zip");
                try
                {
                    ZipFile.CreateFromDirectory(inFolder.Path, to + ".zip");
                }
                catch (Exception)
                {
                }
            }
            return(exitCode);
        }