示例#1
0
        public static void TryReplace(string src, string dest)
        {
            var tmp = TempPath(dest);

            try {
                if (File.Exists(dest))
                {
                    // destがあればswap
                    File.Move(dest, tmp);
                    File.Move(src, dest);
                    File.Delete(src);
                }
                else
                {
                    // なければmove
                    File.Move(src, dest);
                }
            } catch (Exception e) {
                Debugs.Error("FileManager",
                             string.Format("failed to swap files: #{0}, #{1}, #{2}", src, dest, e.Message));
                throw;
            } finally {
                File.Delete(tmp);
            }
        }
示例#2
0
        public static bool Delete(string path)
        {
            var lck = Locks.Get(path);

            lock (lck) {
                try {
                    // 削除済みファイル名に変更
                    TryReplace(path, DeletedPath(path));
                    // そっちを消す
                    File.Delete(DeletedPath(path));
                    return(true);
                } catch (Exception e) {
                    Debugs.Error("Files", "failed delete file: " + path + "," + e.Message);
                    return(false);
                } finally {
                    lck.Dispose();
                }
            }
        }