public bool TryFileMove(string srcFilenameAbsolutePath, string dstFilenameAbsolutePath, Action beforeMoveAction = null, int retries = 3) { if (srcFilenameAbsolutePath == null) { throw new ArgumentNullException(nameof(srcFilenameAbsolutePath)); } if (dstFilenameAbsolutePath == null) { throw new ArgumentNullException(nameof(dstFilenameAbsolutePath)); } if (retries < 0) { throw new ArgumentOutOfRangeException(nameof(retries)); } if (!FileExists(srcFilenameAbsolutePath)) { return(false); } var success = false; SnapUtility.Retry(() => { beforeMoveAction?.Invoke(); FileDeleteIfExists(dstFilenameAbsolutePath, false); FileMove(srcFilenameAbsolutePath, dstFilenameAbsolutePath); success = true; }, retries, 500, false); return(success); }
public bool FileDeleteWithRetries([NotNull] string path, bool ignoreIfFails = false) { if (path == null) { throw new ArgumentNullException(nameof(path)); } try { var success = false; SnapUtility.Retry(() => { FileDelete(path); success = true; }); return(success); } catch (Exception ex) { if (ignoreIfFails) { return(false); } Logger.ErrorException("Really couldn't delete file: " + path, ex); throw; } }