Beispiel #1
0
        private static bool isGoFile(os.FileInfo f)
        {
            // ignore non-Go files
            var name = f.Name();

            return(!f.IsDir() && !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".go"));
        }
Beispiel #2
0
 // hasWritePerm reports whether the current user has permission to write to the
 // file with the given info.
 private static bool hasWritePerm(@string _, os.FileInfo fi)
 {
     // Windows has a read-only attribute independent of ACLs, so use that to
     // determine whether the file is intended to be overwritten.
     //
     // Per https://golang.org/pkg/os/#Chmod:
     // “On Windows, only the 0200 bit (owner writable) of mode is used; it
     // controls whether the file's read-only attribute is set or cleared.”
     return(fi.Mode() & 0200L != 0L);
 }
Beispiel #3
0
                    // hasWritePerm reports whether the current user has permission to write to the
                    // file with the given info.
                    //
                    // Although the root user on most Unix systems can write to files even without
                    // permission, hasWritePerm reports false if no appropriate permission bit is
                    // set even if the current user is root.
                    private static bool hasWritePerm(@string path, os.FileInfo fi)
                    {
                        if (os.Getuid() == 0L)
                        {
                            // The root user can access any file, but we still want to default to
                            // read-only mode if the go.mod file is marked as globally non-writable.
                            // (If the user really intends not to be in readonly mode, they can
                            // pass -mod=mod explicitly.)
                            return(fi.Mode() & 0222L != 0L);
                        }
                        const ulong W_OK = (ulong)0x2UL;

                        return(syscall.Access(path, W_OK) == null);
                    }
Beispiel #4
0
                    // hasWritePerm reports whether the current user has permission to write to the
                    // file with the given info.
                    private static bool hasWritePerm(@string path, os.FileInfo _)
                    {
                        {
                            var(f, err) = os.OpenFile(path, os.O_WRONLY, 0L);

                            if (err == null)
                            {
                                f.Close();
                                return(true);
                            }
                        }

                        return(false);
                    }
Beispiel #5
0
            // FileInfoHeader creates a partially-populated FileHeader from an
            // os.FileInfo.
            // Because os.FileInfo's Name method returns only the base name of
            // the file it describes, it may be necessary to modify the Name field
            // of the returned header to provide the full path name of the file.
            // If compression is desired, callers should set the FileHeader.Method
            // field; it is unset by default.
            public static (ref FileHeader, error) FileInfoHeader(os.FileInfo fi)
            {
                var        size = fi.Size();
                FileHeader fh   = ref new FileHeader(Name: fi.Name(), UncompressedSize64: uint64(size), );

                fh.SetModTime(fi.ModTime());
                fh.SetMode(fi.Mode());
                if (fh.UncompressedSize64 > uint32max)
                {
                    fh.UncompressedSize = uint32max;
                }
                else
                {
                    fh.UncompressedSize = uint32(fh.UncompressedSize64);
                }
                return(fh, null);
            }
Beispiel #6
0
            private static sync.Map userMap = default;        private static sync.Map groupMap = default;// map[int]string

            // map[int]string

            private static error statUnix(os.FileInfo fi, ref Header h)
            {
                ref syscall.Stat_t(sys, ok) = fi.Sys()._ <ref syscall.Stat_t>();
Beispiel #7
0
            private static sync.Map userMap = default;        private static sync.Map groupMap = default;// map[int]string

            // map[int]string

            private static error statUnix(os.FileInfo fi, ptr <Header> _addr_h)
            {
                ref Header h = ref _addr_h.val;
Beispiel #8
0
 public dirFile(@string filePath = default, @string slashPath = default, os.FileInfo info = default)
 {
     this.filePath  = filePath;
     this.slashPath = slashPath;
     this.info      = info;
 }