Пример #1
0
        public override object Call1(Class last_class, object recv, Frame caller, Proc block, object p1)
        {
            string path = String.StringValue(p1, caller);

            FileStat st = new FileStat(path);

            return File.rb_file_ftype(st.stat);
        }
Пример #2
0
        public override object Call(Class last_class, object recv, Frame caller, Proc block, Array rest)
        {
            if (rest.Count == 0)
                throw new ArgumentError("wrong number of arguments").raise(caller);

            char cmd = (char)Integer.rb_num2long(rest[0], caller);

            if (cmd == 0)
                return false;

            if (File.strchr("bcdefgGkloOprRsSuwWxXz", cmd))
            {
                File.test_check(1, rest, caller);

                switch (cmd)
                {
                    case 'b':
                        return test_b.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'c':
                        return test_c.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'd':
                        return test_d.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'a':
                    case 'e':
                        return test_e.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'f':
                        return test_f.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'g':
                        return test_sgid.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'G':
                        return test_grpowned.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'k':
                        return test_sticky.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'l':
                        return test_l.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'o':
                        return test_owned.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'O':
                        return test_owned.singleton.Call1(last_class, null, caller, null, rest[1]);
                        //return test_rowned.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'p':
                        return test_p.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'r':
                        return test_r.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'R':
                        return test_R.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 's':
                        return test_s.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'S':
                        return test_S.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'u':
                        return test_suid.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'w':
                        return test_w.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'W':
                        return test_W.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'x':
                        return test_x.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'X':
                        return test_X.singleton.Call1(last_class, null, caller, null, rest[1]);
                    case 'z':
                        return test_z.singleton.Call1(last_class, null, caller, null, rest[1]);
                }
            }

            if (File.strchr("MAC", cmd))
            {
                File.test_check(1, rest, caller);

                FileStat st = new FileStat(String.StringValue(rest[1], caller));

                switch (cmd)
                {
                    case 'A':
                        return new Time(st.stat.st_atime);
                    case 'M':
                        return new Time(st.stat.st_mtime);
                    case 'C':
                        return new Time(st.stat.st_ctime);
                }
            }

            if (File.strchr("-=<>", cmd))
            {
                File.test_check(2, rest, caller);

                FileStat st1 = new FileStat(String.StringValue(rest[1], caller));
                FileStat st2 = new FileStat(String.StringValue(rest[1], caller));

                switch (cmd)
                {
                    case '-':
                        return (st1.stat.st_dev == st2.stat.st_dev && st1.stat.st_ino == st2.stat.st_ino);
                    case '=':
                        return (st1.stat.st_mtime == st2.stat.st_mtime);
                    case '>':
                        return (st1.stat.st_mtime > st2.stat.st_mtime);
                    case '<':
                        return (st1.stat.st_mtime < st2.stat.st_mtime);
                }
            }

            throw new ArgumentError(string.Format(CultureInfo.InvariantCulture, "unknown command ?{0}", cmd)).raise(caller);
        }
Пример #3
0
 internal static object rb_file_ftype(FileStat.Stat st)
 {
     if (st.fsi is System.IO.DirectoryInfo)
         return new String("directory");
     else if (st.fsi is System.IO.FileInfo)
         return new String("file");
     //else if (st is ?)
     //    return "characterSpecial");
     //else if (st is ?)
     //    return "blockSpecial");
     else
         return new String("unknown");
 }