public void stat_Process(int seqid, TProtocol iprot, TProtocol oprot)
 {
     stat_args args = new stat_args();
     args.Read(iprot);
     iprot.ReadMessageEnd();
     stat_result result = new stat_result();
     try {
       result.Success = iface_.stat(args.Path);
     } catch (ThriftIOException ouch) {
       result.Ouch = ouch;
     }
     oprot.WriteMessageBegin(new TMessage("stat", TMessageType.Reply, seqid));
     result.Write(oprot);
     oprot.WriteMessageEnd();
     oprot.Transport.Flush();
 }
Esempio n. 2
0
        public static object stat(string path) {
            if (path == null) throw PythonOps.TypeError("expected string, got NoneType");

            stat_result sr;

            try {
                FileInfo fi = new FileInfo(path);
                int mode = 0;
                long size;

                if (Directory.Exists(path)) {
                    size = 0;
                    mode = 0x4000 | S_IEXEC;
                } else if (File.Exists(path)) {
                    size = fi.Length;
                    mode = 0x8000;
                    if (HasExecutableExtension(path)) {
                        mode |= S_IEXEC;
                    }
                } else {
                    throw PythonExceptions.CreateThrowable(WindowsError, PythonErrorNumber.ENOENT, "file does not exist: " + path);
                }

                long st_atime = (long)PythonTime.TicksToTimestamp(fi.LastAccessTime.ToUniversalTime().Ticks);
                long st_ctime = (long)PythonTime.TicksToTimestamp(fi.CreationTime.ToUniversalTime().Ticks);
                long st_mtime = (long)PythonTime.TicksToTimestamp(fi.LastWriteTime.ToUniversalTime().Ticks);
                mode |= S_IREAD;
                if ((fi.Attributes & FileAttributes.ReadOnly) == 0) {
                    mode |= S_IWRITE;
                }

                sr = new stat_result(mode, size, st_atime, st_mtime, st_ctime);
            } catch (ArgumentException) {
                throw PythonExceptions.CreateThrowable(WindowsError, PythonErrorNumber.EINVAL, "The path is invalid: " + path);
            } catch (Exception e) {
                throw ToPythonException(e);
            }

            return sr;
        }
 public FileStatus recv_stat()
 {
     TMessage msg = iprot_.ReadMessageBegin();
     if (msg.Type == TMessageType.Exception) {
       TApplicationException x = TApplicationException.Read(iprot_);
       iprot_.ReadMessageEnd();
       throw x;
     }
     stat_result result = new stat_result();
     result.Read(iprot_);
     iprot_.ReadMessageEnd();
     if (result.__isset.success) {
       return result.Success;
     }
     if (result.__isset.ouch) {
       throw result.Ouch;
     }
     throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, "stat failed: unknown result");
 }