1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-07-19 23:16:49 -04:00
parent 794b5a232f
commit 8e041d6e06
834 changed files with 4749 additions and 4461 deletions

View File

@@ -72,7 +72,7 @@ public class Xof_ext_ {
private static final Xof_ext[] Ary = new Xof_ext[Id__max];
public static byte[] Get_ext_by_id_(int id) {
if (id < 0 || id >= Id__max) throw Exc_.new_("index out of bounds", "id", id);
if (id < 0 || id >= Id__max) throw Err_.new_wo_type("index out of bounds", "id", id);
return Bry__ary[id];
}
public static int Get_id_by_ext_(byte[] ext_bry) {

View File

@@ -84,7 +84,7 @@ public class Xof_file_wkr implements Gfo_thread_wkr {
cache_mgr.Update(fsdb);
return true;
} catch (Exception e) {
usr_dlg.Warn_many("", "", "file.unknown: ~{0}", Err_.Message_gplx_brief(e));
usr_dlg.Warn_many("", "", "file.unknown: err=~{0}", Err_.Message_gplx_full(e));
return false;
}
}
@@ -128,7 +128,7 @@ public class Xof_file_wkr implements Gfo_thread_wkr {
bin_updater.Save_bin(mnt_itm, atr_fil, bin_fil, itm, rdr, rdr_len);
}
catch (Exception e) {
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to save file: ttl=~{0} url=~{1} err=~{2}", itm.Orig_ttl(), html_url.Raw(), Err_.Message_gplx(e));
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to save file: ttl=~{0} url=~{1} err=~{2}", itm.Orig_ttl(), html_url.Raw(), Err_.Message_gplx_full(e));
}
finally {rdr.Rls();}
}

View File

@@ -16,9 +16,10 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import gplx.core.consoles.*;
public class Xof_file_wkr_ {
public static final Url_encoder Md5_decoder = Url_encoder.new_http_url_().Itms_raw_same_many(Byte_ascii.Plus);
public static byte[] Md5_fast(byte[] v) {return Bry_.new_a7(gplx.security.HashAlgo_.Md5.CalcHash(ConsoleDlg_.Null, gplx.ios.IoStream_.ary_(v)));}
public static byte[] Md5_fast(byte[] v) {return Bry_.new_a7(gplx.security.HashAlgo_.Md5.CalcHash(Console_adp_.Noop, gplx.ios.IoStream_.ary_(v)));}
public static byte[] Md5_(byte[] ttl) {
ttl = Md5_decoder.Decode_lax(Ttl_standardize(ttl));
return Xof_file_wkr_.Md5_fast(ttl); // NOTE: md5 is calculated off of url_decoded ttl; EX: A%2Cb is converted to A,b and then md5'd. note that A%2Cb still remains the title

View File

@@ -30,7 +30,7 @@ class Xof_wkr_mgr implements GfoInvkAble {
if (String_.Eq(key, "fs.dir"))
rv = new gplx.xowa.files.fsdb.fs_roots.Fs_root_fsdb_mgr(file_mgr.Wiki());
else
throw Exc_.new_unhandled(key);
throw Err_.new_unhandled(key);
file_mgr.Fsdb_mgr_(rv);
return rv;
}

View File

@@ -25,7 +25,7 @@ class Bin_fetcher_fsys implements Bin_fetcher {
public void Init_src_url(Io_url src) {this.src = src;} private Io_url src;
public boolean Save_as_url(Io_url trg) {
try {Io_mgr.I.CopyFil(src, trg, true); return true;}
catch (Exception exc) {Exc_.Noop(exc); return false;}
catch (Exception exc) {Err_.Noop(exc); return false;}
}
public boolean Save_as_bry(Bry_obj_ref bry_ref) {
try {
@@ -33,7 +33,7 @@ class Bin_fetcher_fsys implements Bin_fetcher {
bry_ref.Val_(bry);
return true;
}
catch (Exception exc) {Exc_.Noop(exc); return false;}
catch (Exception exc) {Err_.Noop(exc); return false;}
}
}
class Bin_fetcher_http implements Bin_fetcher {
@@ -48,7 +48,7 @@ class Bin_fetcher_http implements Bin_fetcher {
bry_ref.Val_(rv);
return true;
}
catch (Exception exc) {Exc_.Noop(exc); return false;}
catch (Exception exc) {Err_.Noop(exc); return false;}
}
}
class Bin_fetcher_fsdb {

View File

@@ -39,7 +39,7 @@ public class Xof_bin_skip_mgr {
Xof_bin_skip_wkr rv = null;
if (String_.Eq(key, Xof_bin_skip_wkr_.Key__page_gt_1)) rv = Xof_bin_skip_wkr__page_gt_1.I;
else if (String_.Eq(key, Xof_bin_skip_wkr_.Key__small_size)) rv = Xof_bin_skip_wkr__small_size.I;
else throw Exc_.new_unhandled(key);
else throw Err_.new_unhandled(key);
if (!rv.Skip_init(cfg_mgr)) return null;
return rv;
}

View File

@@ -38,14 +38,14 @@ public class Xof_cache_mgr implements GfoInvkAble {
dir_mgr.Save_all();
fil_mgr.Save_all();
cfg_mgr.Save_all(); // always save cfg_mgr last; fil_mgr / dir_mgr may change next_id during failed saves; DATE:2014-03-07
} catch (Exception e) {usr_dlg.Warn_many("", "", "cache_mgr.save:fatal error: err=~{0}", Err_.Message_gplx_brief(e));}
} catch (Exception e) {usr_dlg.Warn_many("", "", "cache_mgr.save:fatal error: err=~{0}", Err_.Message_gplx_full(e));}
}
public void Db_term() {
try {
cfg_mgr.Cleanup();
dir_mgr.Cleanup();
fil_mgr.Cleanup();
} catch (Exception e) {usr_dlg.Warn_many("", "", "cache_mgr.term:fatal error: err=~{0}", Err_.Message_gplx_brief(e));}
} catch (Exception e) {usr_dlg.Warn_many("", "", "cache_mgr.term:fatal error: err=~{0}", Err_.Message_gplx_full(e));}
}
public Xofc_fil_itm Reg(Xof_fsdb_itm itm, long bin_len) {return this.Reg(itm.Orig_repo_name(), itm.Orig_ttl(), itm.File_is_orig(), itm.File_w(), itm.File_w(), itm.Lnki_time(), itm.Orig_ext(), bin_len, DateAdp_.MaxValue, "");}
private Xofc_fil_itm Reg(byte[] repo, byte[] ttl, boolean fil_is_orig, int fil_w, int fil_h, double fil_thumbtime, Xof_ext ext, long bin_len, DateAdp modified, String hash) {

View File

@@ -50,13 +50,13 @@ class Xofc_dir_tbl implements RlsAble {
case Db_cmd_mode.Tid_update: stmt.Clear() .Val_bry_as_str(fld_name, itm.Name()).Crt_int(fld_id, itm.Id()).Exec_update(); break;
case Db_cmd_mode.Tid_delete: stmt.Clear().Crt_int(fld_id, itm.Id()).Exec_delete(); break;
case Db_cmd_mode.Tid_ignore: break;
default: throw Exc_.new_unhandled(itm.Cmd_mode());
default: throw Err_.new_unhandled(itm.Cmd_mode());
}
itm.Cmd_mode_(Db_cmd_mode.Tid_ignore);
return null;
} catch (Exception e) {
stmt_bldr.Rls(); // rls bldr, else bad stmt will lead to other failures
return Err_.Message_gplx_brief(e);
return Err_.Message_gplx_full(e);
}
}
public void Cleanup() {

View File

@@ -113,7 +113,7 @@ class Xofc_fil_mgr {
this.Save_all(); // save everything again
}
catch (Exception e) {
usr_dlg.Warn_many("", "", "failed to compress cache: err=~{0}", Err_.Message_gplx_brief(e));
usr_dlg.Warn_many("", "", "failed to compress cache: err=~{0}", Err_.Message_gplx_full(e));
}
finally {tbl.Conn().Txn_end();}
}

View File

@@ -68,13 +68,13 @@ class Xofc_fil_tbl implements RlsAble {
case Db_cmd_mode.Tid_update: stmt.Clear(); Db_save_modify(stmt, itm); stmt.Crt_int(fld_uid, itm.Uid()).Exec_update(); break;
case Db_cmd_mode.Tid_delete: stmt.Clear().Crt_int(fld_uid, itm.Uid()); stmt.Exec_delete(); break;
case Db_cmd_mode.Tid_ignore: break;
default: throw Exc_.new_unhandled(itm.Cmd_mode());
default: throw Err_.new_unhandled(itm.Cmd_mode());
}
itm.Cmd_mode_(Db_cmd_mode.Tid_ignore);
return null;
} catch (Exception e) {
stmt_bldr.Rls(); // null out bldr, else bad stmt will lead to other failures
return Err_.Message_gplx_brief(e);
return Err_.Message_gplx_full(e);
}
}
private void Db_save_modify(Db_stmt stmt, Xofc_fil_itm itm) {

View File

@@ -152,7 +152,7 @@ public class Xou_cache_mgr {
conn.Txn_end();
Io_mgr.I.Delete_dir_empty(cache_dir);
}
catch (Exception e) {Xoa_app_.Usr_dlg().Warn_many("", "", "failed to compress cache: err=~{0}", Err_.Message_gplx_brief(e)); return;}
catch (Exception e) {Xoa_app_.Usr_dlg().Warn_many("", "", "failed to compress cache: err=~{0}", Err_.Message_gplx_full(e)); return;}
}
Xoa_app_.Usr_dlg().Note_many("", "", "cache compress done");
}

View File

@@ -107,10 +107,10 @@ public class Xou_cache_tbl implements RlsAble {
case Db_cmd_mode.Tid_update: stmt.Clear(); Db_save_val(stmt, itm); Db_save_crt(stmt, itm, Bool_.N); stmt.Exec_update(); break;
case Db_cmd_mode.Tid_delete: stmt.Clear(); Db_save_crt(stmt, itm, Bool_.N); stmt.Exec_delete(); break;
case Db_cmd_mode.Tid_ignore: break;
default: throw Exc_.new_unhandled(itm.Db_state());
default: throw Err_.new_unhandled(itm.Db_state());
}
itm.Db_state_(Db_cmd_mode.Tid_ignore);
} catch (Exception e) {stmt_bldr.Rls(); throw Exc_.new_exc(e, "xo", "db_save failed");}
} catch (Exception e) {stmt_bldr.Rls(); throw Err_.new_exc(e, "xo", "db_save failed");}
}
@gplx.Internal protected Db_rdr Select_all_for_test() {return conn.Stmt_select(tbl_name, flds, Db_meta_fld.Ary_empty).Exec_select__rls_manual();}
private void Db_save_crt(Db_stmt stmt, Xou_cache_itm itm, boolean insert) {

View File

@@ -55,7 +55,7 @@ public class Xou_file_itm_finder {
else
return false;
} catch (Exception e) {
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to find img: img=~{0} err=~{1}", lnki_ttl, Err_.Message_gplx_brief(e));
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to find img: img=~{0} err=~{1}", lnki_ttl, Err_.Message_gplx_log(e));
return false;
}
}

View File

@@ -21,7 +21,7 @@ public class Xof_img_wkr_resize_img_mok implements Xof_img_wkr_resize_img {
public boolean Resize_exec(Io_url src, Io_url trg, int trg_w, int trg_h, int ext_id, String_obj_ref rslt_val) {
SizeAdp src_size = ImageAdp_.txt_fil_(src).Size();
int src_w = src_size.Width(), src_h = src_size.Height();
if (trg_w < 1) throw Exc_.new_("trg_w must be > 0", "trg_w", trg_w);
if (trg_w < 1) throw Err_.new_wo_type("trg_w must be > 0", "trg_w", trg_w);
if (trg_h < 1) trg_h = Xof_xfer_itm_.Scale_h(src_w, src_h, trg_w);
Io_mgr.I.SaveFilStr(trg, SizeAdp_.new_(trg_w, trg_h).XtoStr());
return true;

View File

@@ -33,7 +33,7 @@ public class Xof_download_wkr_io implements Xof_download_wkr {
Io_url src_url = Io_url_.new_fil_(src_str);
if (!Io_mgr.I.ExistsFil(src_url)) return IoEngine_xrg_downloadFil.Rslt_fail_file_not_found;
try {Io_mgr.I.CopyFil(src_url, trg_url, true);}
catch (Exception exc) {Exc_.Noop(exc); return IoEngine_xrg_downloadFil.Rslt_fail_unknown;}
catch (Exception exc) {Err_.Noop(exc); return IoEngine_xrg_downloadFil.Rslt_fail_unknown;}
return IoEngine_xrg_downloadFil.Rslt_pass;
}
}

View File

@@ -24,7 +24,7 @@ public class Xof_download_wkr_test implements Xof_download_wkr {
Io_url src_url = Io_url_.new_fil_(src_str);
if (!Io_mgr.I.ExistsFil(src_url)) return IoEngine_xrg_downloadFil.Rslt_fail_file_not_found;
try {Io_mgr.I.CopyFil(src_url, trg_url, true);}
catch (Exception exc) {Exc_.Noop(exc); return IoEngine_xrg_downloadFil.Rslt_fail_unknown;}
catch (Exception exc) {Err_.Noop(exc); return IoEngine_xrg_downloadFil.Rslt_fail_unknown;}
return IoEngine_xrg_downloadFil.Rslt_pass;
}
}

View File

@@ -41,7 +41,7 @@ public class Xof_fsdb_mgr__sql implements Xof_fsdb_mgr, GfoInvkAble {
this.bin_mgr = new Xof_bin_mgr(mnt_mgr, repo_mgr, wiki.App().File__img_mgr().Wkr_resize_img(), wiki.App().Wmf_mgr().Download_wkr().Download_xrg().Download_fmt());
bin_mgr.Wkrs__add(Xof_bin_wkr__fsdb_sql.new_(mnt_mgr));
bin_mgr.Wkrs__add(Xof_bin_wkr__http_wmf.new_(wiki));
} catch (Exception e) {throw Exc_.new_exc(e, "xo", "failed to initialize fsdb_mgr}", "wiki", wiki.Domain_str());}
} catch (Exception e) {throw Err_.new_exc(e, "xo", "failed to initialize fsdb_mgr}", "wiki", wiki.Domain_str());}
}
public void Fsdb_search_by_list(List_adp itms, Xow_wiki cur_wiki, Xoa_page page, Xog_js_wkr js_wkr) {
if (!fsdb_enabled) return;

View File

@@ -43,7 +43,7 @@ public class Fs_root_fsdb_mgr implements Xof_fsdb_mgr, GfoInvkAble { // read ima
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_root_dir_ = "root_dir_", Invk_orig_dir_ = "orig_dir_", Invk_thumb_dir_ = "thumb_dir_";
public Xof_bin_mgr Bin_mgr() {throw Exc_.new_unimplemented();}
public Xof_bin_mgr Bin_mgr() {throw Err_.new_unimplemented();}
public Fsm_mnt_mgr Mnt_mgr() {return null;}
public void Rls() {}
}

View File

@@ -66,7 +66,7 @@ public class Xof_orig_mgr {
if (!Io_mgr.I.ExistsFil(fsdb.Html_view_url()))
fsdb.File_exists_n_();
} catch (Exception e) {
Xoa_app_.Usr_dlg().Warn_many("", "", "orig: ~{0}", Err_.Message_gplx_brief(e));
Xoa_app_.Usr_dlg().Warn_many("", "", "orig: exc=~{0}", Err_.Message_gplx_full(e));
}
}
}

View File

@@ -73,7 +73,7 @@ public class Xof_repo_itm implements GfoInvkAble {
return Xof_repo_itm_.Ttl_shorten_ttl(tmp_bfr, rv, ttl_max_len, md5, ext.Ext());
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_owner)) throw Exc_.new_unimplemented_w_msg("deprecated repo_itm.owner");
if (ctx.Match(k, Invk_owner)) throw Err_.new_unimplemented_w_msg("deprecated repo_itm.owner");
else if (ctx.Match(k, Invk_fsys_)) fsys_is_wnt = String_.Eq(m.ReadStr("v"), "wnt");
else if (ctx.Match(k, Invk_primary_)) primary = m.ReadYn("v");
else if (ctx.Match(k, Invk_ext_rules_)) Ext_rules_(m.ReadBry("v"));

View File

@@ -21,7 +21,7 @@ public class Xof_repo_itm_ {
public static final int Dir_depth_null = -1, Dir_depth_wmf = 2, Dir_depth_xowa = 4;
public static final byte Mode_orig = 0, Mode_thumb = 1, Mode_nil = Byte_.Max_value_127;
public static byte Mode_by_bool(boolean is_thumb) {return is_thumb ? Mode_thumb : Mode_orig;}
public static final byte[][] Mode_names_key = new byte[][] {Bry_.new_u8("orig"), Bry_.new_u8("thumb")};
public static final byte[][] Mode_names_key = new byte[][] {Bry_.new_a7("orig"), Bry_.new_a7("thumb")};
public static final byte Repo_remote = 0, Repo_local = 1, Repo_unknown = 126, Repo_null = Byte_.Max_value_127;
public static byte Repo_by_bool(boolean is_commons) {return is_commons ? Repo_remote : Repo_local;}
public static boolean Repo_is_known(byte repo) {

View File

@@ -192,7 +192,7 @@ public class Xowe_repo_mgr implements Xow_repo_mgr, GfoInvkAble {
Xoa_repo_mgr repo_mgr = wiki.Appe().File_mgr().Repo_mgr();
Xof_repo_itm src_repo = repo_mgr.Get_by(src_repo_key), trg_repo = repo_mgr.Get_by(trg_repo_key);
byte[] src_wiki_key = src_repo.Wiki_domain(), trg_wiki_key = trg_repo.Wiki_domain();
if (!Bry_.Eq(src_wiki_key, trg_wiki_key) && !Bry_.Eq(src_wiki_key, Xow_domain_type_.Key_bry_home)) throw Exc_.new_("wiki keys do not match", "src", String_.new_u8(src_wiki_key), "trg", String_.new_u8(trg_wiki_key));
if (!Bry_.Eq(src_wiki_key, trg_wiki_key) && !Bry_.Eq(src_wiki_key, Xow_domain_type_.Key_bry_home)) throw Err_.new_wo_type("wiki keys do not match", "src", String_.new_u8(src_wiki_key), "trg", String_.new_u8(trg_wiki_key));
Xof_repo_pair pair = new Xof_repo_pair((byte)repos.Count(), src_wiki_key, src_repo, trg_repo);
repos.Add(pair);
return pair;

View File

@@ -313,7 +313,7 @@ public class Xof_xfer_mgr {
Io_url new_trg = trg_url.GenNewNameOnly(new_name);
if (trg_url.Eq(new_trg)) return true; // HACK: io will delete file if moving unto itself; (i.e.: mv A.png A.png is same as del A.png); problem is that this proc is being called too many times
try {Io_mgr.I.MoveFil_args(trg_url, new_trg, true).Exec();}
catch (Exception exc) {Exc_.Noop(exc); return rslt.Fail("move failed");}
catch (Exception exc) {Err_.Noop(exc); return rslt.Fail("move failed");}
rslt.Trg_(new_trg);
}
return true;
@@ -331,7 +331,7 @@ public class Xof_xfer_mgr {
byte download_rslt = wmf_mgr.Download_wkr().Download(src_repo_is_wmf, src_str, trg_url, wmf_mgr.Download_wkr().Download_xrg().Prog_fmt_hdr());
if (download_rslt == gplx.ios.IoEngine_xrg_downloadFil.Rslt_fail_host_not_found) {
wiki.File_mgr().Cfg_download().Enabled_(false);
throw Exc_.new_("download_failed: host not found", "src", src_str, "trg", trg_url.Raw());
throw Err_.new_wo_type("download_failed: host not found", "src", src_str, "trg", trg_url.Raw());
}
pass = download_rslt == gplx.ios.IoEngine_xrg_downloadFil.Rslt_pass;
}