vorteil/vorteil

View on GitHub
pkg/xfs/xfs.go

Summary

Maintainability
F
1 wk
Test Coverage

File xfs.go has 1127 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package xfs

import (
    "bytes"
    "context"
Severity: Major
Found in pkg/xfs/xfs.go - About 2 days to fix

    Method compiler.writeAllocGroup has 304 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (c *compiler) writeAllocGroup(ctx context.Context, w io.WriteSeeker, ag int64) error {
        var err error
    
        allocGroupOffset := ag * c.blocksPerAllocGroup() * c.blockSize()
        _, err = w.Seek(allocGroupOffset, io.SeekStart)
    Severity: Major
    Found in pkg/xfs/xfs.go - About 1 day to fix

      Method precompiler.calculateMinimumSize has a Cognitive Complexity of 74 (exceeds 20 allowed). Consider refactoring.
      Open

      func (p *precompiler) calculateMinimumSize(ctx context.Context) error {
      
          var err error
      
          p.allocGroups = 1
      Severity: Minor
      Found in pkg/xfs/xfs.go - About 1 day to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method compiler.writeAllocGroup has a Cognitive Complexity of 73 (exceeds 20 allowed). Consider refactoring.
      Open

      func (c *compiler) writeAllocGroup(ctx context.Context, w io.WriteSeeker, ag int64) error {
          var err error
      
          allocGroupOffset := ag * c.blocksPerAllocGroup() * c.blockSize()
          _, err = w.Seek(allocGroupOffset, io.SeekStart)
      Severity: Minor
      Found in pkg/xfs/xfs.go - About 1 day to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method precompiler.calculateMinimumSize has 147 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (p *precompiler) calculateMinimumSize(ctx context.Context) error {
      
          var err error
      
          p.allocGroups = 1
      Severity: Major
      Found in pkg/xfs/xfs.go - About 4 hrs to fix

        Method compiler.popInode has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring.
        Open

        func (c *compiler) popInode() io.Reader {
        
            n, more := <-c.nodes
            if !more {
                return nil
        Severity: Minor
        Found in pkg/xfs/xfs.go - About 3 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method compiler.popInode has 104 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (c *compiler) popInode() io.Reader {
        
            n, more := <-c.nodes
            if !more {
                return nil
        Severity: Major
        Found in pkg/xfs/xfs.go - About 3 hrs to fix

          Method compiler.writeAllocGroup has 34 return statements (exceeds 4 allowed).
          Open

          func (c *compiler) writeAllocGroup(ctx context.Context, w io.WriteSeeker, ag int64) error {
              var err error
          
              allocGroupOffset := ag * c.blocksPerAllocGroup() * c.blockSize()
              _, err = w.Seek(allocGroupOffset, io.SeekStart)
          Severity: Major
          Found in pkg/xfs/xfs.go - About 3 hrs to fix

            Method compiler.precompile has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
            Open

            func (c *compiler) precompile(ctx context.Context) error {
            
                var err error
            
                // alloc group sizes
            Severity: Minor
            Found in pkg/xfs/xfs.go - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method compiler.buildBitmap has 58 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (c *compiler) buildBitmap() {
                c.allocGroupFreeBlocks = make([]int64, c.allocGroups)
                c.allocGroupFreeInodes = make([]int64, c.allocGroups)
            
                for i := int64(0); i < c.allocGroups; i++ {
            Severity: Minor
            Found in pkg/xfs/xfs.go - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                                  if lfll > p.directoryBlockSize() {
                                      // directory must be stored in node form
                                      x = ddb // data blocks
                                      x += 1  // node block
              
              
              Severity: Major
              Found in pkg/xfs/xfs.go - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                            if err != nil {
                                panic(err) // NOTE: this is only supported if the filetree supports looking up and caching this value in advance, which should make errors impossible
                            }
                Severity: Major
                Found in pkg/xfs/xfs.go - About 45 mins to fix

                  Method precompiler.calculateMinimumSize has 6 return statements (exceeds 4 allowed).
                  Open

                  func (p *precompiler) calculateMinimumSize(ctx context.Context) error {
                  
                      var err error
                  
                      p.allocGroups = 1
                  Severity: Major
                  Found in pkg/xfs/xfs.go - About 40 mins to fix

                    Method precompiler.setBlockSize has 5 return statements (exceeds 4 allowed).
                    Open

                    func (p *precompiler) setBlockSize(size int64) error {
                    
                        if size == 0 {
                            p.exponents.blockSize = 12 // 4 KiB
                            return nil
                    Severity: Major
                    Found in pkg/xfs/xfs.go - About 35 mins to fix

                      Method compiler.buildBitmap has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                      Open

                      func (c *compiler) buildBitmap() {
                          c.allocGroupFreeBlocks = make([]int64, c.allocGroups)
                          c.allocGroupFreeInodes = make([]int64, c.allocGroups)
                      
                          for i := int64(0); i < c.allocGroups; i++ {
                      Severity: Minor
                      Found in pkg/xfs/xfs.go - About 35 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Method precompiler.Precompile has 5 return statements (exceeds 4 allowed).
                      Open

                      func (p *precompiler) Precompile(ctx context.Context, fsSize int64) (*compiler, error) {
                      
                          var err error
                      
                          c := &compiler{
                      Severity: Major
                      Found in pkg/xfs/xfs.go - About 35 mins to fix

                        TODO found
                        Open

                                    // TODO: var ln int64 // length (node form)
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by fixme

                        TODO found
                        Open

                            // distribute nodes amongst alloc groups TODO: see if files can be spread out better amongst the alloc groups
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by fixme

                        TODO found
                        Open

                                    panic(errors.New("super nested extents not yet supported")) // TODO
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by fixme

                        TODO found
                        Open

                                // TODO: improve performance here by treating uint64s instead of bits
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by fixme

                        TODO found
                        Open

                            c.nodes = make(chan *vio.TreeNode) // TODO: close this safely
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by fixme

                        TODO found
                        Open

                                recHeader.CycleData[0] = 0xB0C0D0D0 // TODO: figure out what this is supposed to mean.
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by fixme

                        TODO found
                        Open

                                    // TODO: check this (I'm suspicious of the quality of my work when I wrote it)
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by fixme

                        TODO found
                        Open

                                    // TODO: does this work?
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by fixme

                        TODO found
                        Open

                                Count:     uint32(c.inodesPerAllocGroup()), // TODO: - c.allocGroupFreeInodes[ag]), -- is it meant to be this way?
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by fixme

                        TODO found
                        Open

                                // ExtSize TODO: is this necessary?
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by fixme

                        TODO found
                        Open

                                        // TODO: shuffle entries to optimize used space
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by fixme

                        TODO found
                        Open

                            c.data = make(chan *vio.TreeNode)  // TODO: close this safely
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by fixme

                        TODO found
                        Open

                        func (c *constants) inodeBlocksPerAllocGroup() int64 { // TODO: unit test if it's possible to get an odd number out of this (I'm suspicious...)
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by fixme

                        TODO found
                        Open

                                    Unknown:       0x6E55, // TODO: Figure out what this is supposed to mean.
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by fixme

                        Identical blocks of code found in 2 locations. Consider refactoring.
                        Open

                                } else if n.File.IsSymlink() {
                                    // TODO: does this work?
                                    _ = c.computeNodeExtents(n.NodeSequenceNumber, &dataRange{blocks: c.dataReaderBlocksRemaining}) // called here to ensure things are computed in order
                                    c.dataReader = io.MultiReader(n.File, io.LimitReader(vio.Zeroes, c.dataReaderBlocksRemaining*c.blockSize()-int64(n.File.Size())))
                                } else {
                        Severity: Minor
                        Found in pkg/xfs/xfs.go and 1 other location - About 30 mins to fix
                        pkg/xfs/xfs.go on lines 1136..1139

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 101.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Identical blocks of code found in 2 locations. Consider refactoring.
                        Open

                                } else {
                                    _ = c.computeNodeExtents(n.NodeSequenceNumber, &dataRange{blocks: c.dataReaderBlocksRemaining}) // called here to ensure things are computed in order
                                    c.dataReader = io.MultiReader(n.File, io.LimitReader(vio.Zeroes, c.dataReaderBlocksRemaining*c.blockSize()-int64(n.File.Size())))
                                }
                        Severity: Minor
                        Found in pkg/xfs/xfs.go and 1 other location - About 30 mins to fix
                        pkg/xfs/xfs.go on lines 1132..1136

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 101.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Your code does not pass gofmt in 1 place. Go fmt your code!
                        Open

                        package xfs
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by gofmt

                        should replace x += 1 with x++
                        Open

                                                x += 1  // node block
                        Severity: Minor
                        Found in pkg/xfs/xfs.go by golint

                        There are no issues that match your filters.

                        Category
                        Status