Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

orphaned lock removal (3 mins timeout)

  • Loading branch information...
commit 5d39b514683424d814eb7a9ded560dac7d8907d6 1 parent 1e7824a
a-fung authored
28 source/aspnetserver/Manga.cs
View
@@ -676,7 +676,7 @@ public string GetCover()
string coverRelativePath = "cover/" + hash + ".jpg";
string coverPath = Path.Combine(AjaxBase.DirectoryPath, "cover", hash + ".jpg");
- if (File.Exists(lockPath))
+ if (CheckLockFile(lockPath))
{
return null;
}
@@ -709,7 +709,7 @@ public string GetPage(int page, int width, int height, int part)
string outputRelativePath = "mangacache/" + hash + ".jpg";
string outputPath = Path.Combine(AjaxBase.DirectoryPath, "mangacache", hash + ".jpg");
- if (File.Exists(lockPath))
+ if (CheckLockFile(lockPath))
{
return null;
}
@@ -724,6 +724,30 @@ public string GetPage(int page, int width, int height, int part)
}
}
+ private bool CheckLockFile(string lockPath)
+ {
+ if (File.Exists(lockPath))
+ {
+ FileInfo lockFileInfo = new FileInfo(lockPath);
+ if (DateTime.UtcNow - lockFileInfo.CreationTimeUtc > TimeSpan.FromMinutes(3))
+ {
+ try
+ {
+ lockFileInfo.Delete();
+ return false;
+ }
+ catch (Exception ex)
+ {
+ Utility.TryLogError(ex);
+ }
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
private string TryOutputFile(string content)
{
string tempFilePath = null;
29 source/haxe/afung/mangaWeb3/server/Manga.hx
View
@@ -644,7 +644,7 @@ class Manga
var coverRelativePath:String = "cover/" + hash + ".jpg";
var coverPath:String = coverRelativePath;
- if (FileSystem.exists(lockPath))
+ if (CheckLockFile(lockPath))
{
return null;
}
@@ -677,7 +677,7 @@ class Manga
var outputRelativePath:String = "mangacache/" + hash + ".jpg";
var outputPath:String = outputRelativePath;
- if (FileSystem.exists(lockPath))
+ if (CheckLockFile(lockPath))
{
return null;
}
@@ -692,6 +692,29 @@ class Manga
}
}
+ private function CheckLockFile(lockPath:String):Bool
+ {
+ if (FileSystem.exists(lockPath))
+ {
+ if (Date.now().getTime() - FileSystem.stat(lockPath).ctime.getTime() > 180000)
+ {
+ try
+ {
+ FileSystem.deleteFile(lockPath);
+ return false;
+ }
+ catch (ex:Dynamic)
+ {
+ Utility.TryLogError(ex);
+ }
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
private function TryOutputFile(content:String):String
{
var tempFilePath:String = null;
@@ -725,7 +748,7 @@ class Manga
{
if (!FileSystem.exists(outputPath))
{
- var lockFile:Dynamic = null;
+ var lockFile:Dynamic = false;
try
{
lockFile = untyped __call__("@fopen", lockPath, "x");
20 source/scriptsharp/Module/MangasModule.cs
View
@@ -52,7 +52,10 @@ private MangasModule()
protected override void OnBeforeShow()
{
- jQuery.Select("#mangas-list").Children().Remove();
+ if (items.Length > 0)
+ {
+ jQuery.Select("#mangas-list").Children().Remove();
+ }
}
protected override void OnShow()
@@ -159,6 +162,18 @@ private void MangaListRequestSuccess(MangaListResponse response)
jQuery.Select("#mangas-loading").Children().Remove();
items = response.items;
+ SortItems();
+
+ ChangePage(1);
+ pagination.Refresh(true);
+ }
+
+ public void SortItems()
+ {
+ if (items.Length == 0)
+ {
+ return;
+ }
CompareCallback<MangaListItemJson> compare = null;
@@ -209,9 +224,6 @@ private void MangaListRequestSuccess(MangaListResponse response)
{
((List<MangaListItemJson>)(object)items).Sort(compare);
}
-
- ChangePage(1);
- pagination.Refresh(true);
}
private int GetTotalPage()
9 source/scriptsharp/Module/SettingsModule.cs
View
@@ -51,7 +51,6 @@ private void ApplyChange(jQueryEvent e)
{
e.PreventDefault();
- Settings.Sort = int.Parse(jQuery.Select("#settings-sort").GetValue(), 10);
Settings.DisplayType = int.Parse(jQuery.Select("#settings-display-type").GetValue(), 10);
Settings.FixAutoDownscale = jQuery.Select("#settings-fix-auto-downscale").GetAttribute("checked") == "checked";
@@ -60,6 +59,14 @@ private void ApplyChange(jQueryEvent e)
{
Settings.UserLanguage = newLanguage;
Window.Location.Href = "index.html";
+ return;
+ }
+
+ int newSort = int.Parse(jQuery.Select("#settings-sort").GetValue(), 10);
+ if (newSort != Settings.Sort)
+ {
+ Settings.Sort = newSort;
+ MangasModule.Instance.SortItems();
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.