Пример #1
0
        /// <summary>
        /// Copy file
        /// </summary>
        /// <param name="from">can be any valid file name - no form requirements</param>
        /// <returns></returns>
        public int cp(string from)
        {
            var newname = Os.winInternal(FullName);

            rm();
            File.Copy(from, newname, true);
            #region double check if file has moved
            if (Ensure)
            {
                return(awaitFileMaterializing(newname));
            }
            #endregion
            return(0);
        }
Пример #2
0
        /// <summary>
        /// throws exception if dir is not empty
        /// </summary>
        /// <param name="path">must point to a directory</param>
        private static void rmdir(string path)
        {
            path = Os.winInternal(path);
            var dir = new DirectoryInfo(path);

            if (dir.Exists)
            {
                Directory.Delete(path);
                if (path.ToLower().Contains("dropbox"))
                {
                    awaitDirVanishing(path);
                }
            }
        }
Пример #3
0
        /// <summary>Create a directory if it does not exist yet</summary>
        /// <param name="dirname"></param>
        /// <returns>DirectoryInfo structure; contains properties Exists and CreationDate</returns>
        public static DirectoryInfo mkdir(string dirname)
        {
            dirname = Os.winInternal(string.IsNullOrEmpty(dirname) ? Directory.GetCurrentDirectory() : dirname);
            var dir = new DirectoryInfo(dirname);

            if (!dir.Exists)              // TODO problems with network drives, i.e. IservSetting.RemoteRootDir
            {
                dir = Directory.CreateDirectory(dirname);
                if (dirname.ToLower().Contains("dropbox"))
                {
                    awaitDirMaterializing(dirname);
                }
            }
            return(dir);
        }
Пример #4
0
        /// <summary>
        /// Copy file
        /// </summary>
        /// <param name="from">will be checked; exception will be thrown if file name does not match RsbFile form requirements</param>
        /// <returns>0 if everything went well</returns>
        public int cp(RaiFile from)
        {         // copy file in the file system
            var oldname = Os.winInternal(from.FullName);
            var newname = Os.winInternal(FullName);

            rm();                              // make sure it's really gone before we go ahead; applies ensure
            File.Copy(oldname, newname, true); // overwrite if exists (which should never happen since we just removed it)
            #region double check if file has moved
            if (Ensure)
            {
                return(awaitFileMaterializing(newname));
            }
            #endregion
            return(0);
        }
Пример #5
0
        public int rm()         // removes file from the file system
        {
            var name = Os.winInternal(FullName);

            if (File.Exists(name))
            {
                File.Delete(name);
                #region double check if file is gone
                if (Ensure)
                {
                    return(awaitFileVanishing(name));
                }
                #endregion
            }
            return(0);
        }
Пример #6
0
        public int mv(RaiFile from)                 // relocates file in the file system
        {
            //bool destIsDropbox = Name.ToLower().Contains("dropbox");
            //bool srcIsDropbox = from.Name.ToLower().Contains("dropbox");
            //#region both files in Dropbox - no acceleration
            //#endregion
            mkdir();             // create destdir if necessary; applies ensure
            var newname = Os.winInternal(FullName);
            var oldname = Os.winInternal(from.FullName);

            rm();                        // make sure it's really gone before we go ahead; applies ensure
            File.Move(oldname, newname); // make sure the user that w3wp runs under has write/delete access to oldname, i.e. c:\dropbox\config\3.3.3\Users.xml
            #region double check if file has moved
            if (Ensure)
            {
                return(awaitFileVanishing(oldname) + awaitFileMaterializing(newname));
            }
            #endregion
            return(0);
        }
Пример #7
0
 public static string Escape(string s, EscapeMode mode)
 {
     if (mode == EscapeMode.noEsc)
     {
         return(s);
     }
     if (mode == EscapeMode.blankEsc)
     {
         return(Os.escapeBlank(s));
     }
     if (mode == EscapeMode.paramEsc)
     {
         return(Os.escapeParam(s));
     }
     if (mode == EscapeMode.backslashed)
     {
         return(Os.winInternal(s));
     }
     return(s);
 }
Пример #8
0
 /// <summary>
 /// Constructor: auto-ensure mode for file systems that do not synchronously wait for the end of an IO operation i.e. Dropbox
 /// </summary>
 /// <remarks>only use the ensure mode if it has to be guaranteed that the IO operation was completely done
 /// when the method call returns; necessary e.g. for Dropbox directories since (currently) Dropbox first updates the
 /// file in the invisible . folder and then asynchronously updates the visible file and all the remote copies of it</remarks>
 /// <param name="filename"></param>
 public RaiFile(string filename)
 {
     Ensure = filename.ToLower().Contains("dropbox");
     path   = string.Empty;
     name   = string.Empty;
     ext    = string.Empty;
     if (!string.IsNullOrEmpty(filename))
     {
         #region some unix conventions for convenience
         if (filename.StartsWith("~/"))
         {
             filename = $"{Os.HomeDir}{filename.Substring(1)}";
         }
         else if (filename.StartsWith("./"))
         {
             filename = $"{Directory.GetCurrentDirectory()}{filename.Substring(1)}";
         }
         else if (filename.StartsWith("../"))
         {
             var dir = Directory.GetCurrentDirectory();
             while (filename.StartsWith("../"))
             {
                 dir      = new RaiFile(dir.TrimEnd('/')).Path;                      // one up
                 filename = filename.Substring(3);                                   // remove first ../
             }
             filename = $"{dir}{filename}";
         }
         #endregion
         filename = Os.NormSeperator(filename);
         var k = filename.LastIndexOf(Os.DIRSEPERATOR);
         if (k >= 0)
         {
             path = filename.Substring(0, k + 1);
             Name = filename.Substring(k + 1);
         }
         else
         {
             Name = filename;                    // also takes care of ext
         }
     }
 }
Пример #9
0
 /// <summary>
 /// Check if the file currently exists in the file system
 /// </summary>
 /// <returns></returns>
 public bool Exists()
 {
     return(File.Exists(Os.winInternal(FullName)));
 }