Skip to content

Commit

Permalink
Don't use the "soft" magic db
Browse files Browse the repository at this point in the history
It doesn't help us determine if the file is binary or not, and just
seems to create a bunch of problems like the ones in #4
  • Loading branch information
Scott J. Goldman authored and brianmario committed Mar 8, 2013
1 parent 4b2478e commit 0989ca9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 1 addition & 5 deletions ext/charlock_holmes/encoding_detector.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,11 @@ static VALUE rb_encdec__alloc(VALUE klass)
rb_raise(rb_eStandardError, "%s", u_errorName(status));
}

detector->magic = magic_open(0);
detector->magic = magic_open(MAGIC_NO_CHECK_SOFT);
if (detector->magic == NULL) {
rb_raise(rb_eStandardError, "%s", magic_error(detector->magic));
}

// load the libmagic database
// NULL means use the default or whatever is specified by the MAGIC env var
magic_load(detector->magic, NULL);

return obj;
}

Expand Down
1 change: 1 addition & 0 deletions ext/charlock_holmes/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def sys(cmd)
sys("tar zxvf #{src}")
Dir.chdir(dir) do
sys("./configure --prefix=#{CWD}/dst/ --disable-shared --enable-static --with-pic")
sys("patch -p0 < ../file-soft-check.patch")
sys("make -C src install")
sys("make -C magic install")
end
Expand Down
11 changes: 11 additions & 0 deletions ext/charlock_holmes/src/file-soft-check.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- src/funcs.c.orig 2013-01-27 01:23:01.000000000 -0800
+++ src/funcs.c 2013-01-27 01:23:46.000000000 -0800
@@ -300,7 +300,7 @@
protected int
file_reset(struct magic_set *ms)
{
- if (ms->mlist == NULL) {
+ if (!(ms->flags & MAGIC_NO_CHECK_SOFT) && ms->mlist == NULL) {
file_error(ms, 0, "no magic files loaded");
return -1;
}

0 comments on commit 0989ca9

Please sign in to comment.