afero icon indicating copy to clipboard operation
afero copied to clipboard

MemMapFs + afero.Walk -> infinite loop

Open Ma124 opened this issue 6 years ago • 0 comments

I have an MemMapFs with the following structure:

([]os.FileInfo) (len=1 cap=1) {
 (*mem.FileInfo)(0xc420098080)({
  FileData: (*mem.FileData)(0xc4200a6300)({
   Mutex: (sync.Mutex) {
    state: (int32) 0,
    sema: (uint32) 0
   },
   name: (string) (len=44) "abc.txt_a3171851-d16d-4b27-a790-1a4d3d4f221a",
   data: ([]uint8) (len=11 cap=16) {
    00000000  48 65 6c 6c 6f 20 47 6f  6c 70 21                 |Hello Golp!|
   },
   memDir: (mem.Dir) <nil>,
   dir: (bool) false,
   mode: (os.FileMode) T---------,
   modtime: (time.Time) 2018-12-01 09:58:08.052452176 +0100 CET m=+0.001122979
  })
 })
}

(One file named: abc.txt_a3171851-d16d-4b27-a790-1a4d3d4f221a)

So it should only call the walkFn once.

afero.Walk(i.Fs(), "/", func(path string, info os.FileInfo, err error) error {
	spew.Dump(info)
	return nil
})

But the above code results in:

(*mem.FileInfo)(0xc42000e088)({
 FileData: (*mem.FileData)(0xc420068300)({
  Mutex: (sync.Mutex) {
   state: (int32) 0,
   sema: (uint32) 0
  },
  name: (string) (len=1) "/",
  data: ([]uint8) <nil>,
  memDir: (*mem.DirMap)(0xc42000e078)((len=1) {
   (string) (len=44) "abc.txt_2d83e30d-bf11-4953-8ebb-fdb2e91235cc": (*mem.FileData)(0xc420068360)({
    Mutex: (sync.Mutex) {
     state: (int32) 0,
     sema: (uint32) 0
    },
    name: (string) (len=44) "abc.txt_2d83e30d-bf11-4953-8ebb-fdb2e91235cc",
    data: ([]uint8) (len=11 cap=16) {
     00000000  48 65 6c 6c 6f 20 47 6f  6c 70 21                 |Hello Golp!|
    },
    memDir: (mem.Dir) <nil>,
    dir: (bool) false,
    mode: (os.FileMode) T---------,
    modtime: (time.Time) 2018-12-01 09:53:37.422059676 +0100 CET m=+0.001065426
   })
  }),
  dir: (bool) true,
  mode: (os.FileMode) ----------,
  modtime: (time.Time) 0001-01-01 00:00:00 +0000 UTC
 })
})
(*mem.FileInfo)(0xc42000e100)({
 FileData: (*mem.FileData)(0xc420068600)({
  Mutex: (sync.Mutex) {
   state: (int32) 0,
   sema: (uint32) 0
  },
  name: (string) (len=1) "/",
  data: ([]uint8) <nil>,
  memDir: (*mem.DirMap)(0xc42000e0b0)((len=1) {
   (string) (len=1) "/": (*mem.FileData)(0xc420068600)(<already shown>)
  }),
  dir: (bool) true,
  mode: (os.FileMode) T---------,
  modtime: (time.Time) 2018-12-01 09:53:37.424199616 +0100 CET m=+0.003205398
 })
})
(*mem.FileInfo)(0xc420174010)({
 FileData: (*mem.FileData)(0xc420068720)({
  Mutex: (sync.Mutex) {
   state: (int32) 0,
   sema: (uint32) 0
  },
  name: (string) (len=1) "/",
  data: ([]uint8) <nil>,
  memDir: (*mem.DirMap)(0xc42000e110)((len=1) {
   (string) (len=1) "/": (*mem.FileData)(0xc420068720)(<already shown>)
  }),
  dir: (bool) true,
  mode: (os.FileMode) T---------,
  modtime: (time.Time) 2018-12-01 09:53:37.425307087 +0100 CET m=+0.004312958
 })
})
(*mem.FileInfo)(0xc420174070)({
 FileData: (*mem.FileData)(0xc42017e0c0)({
  Mutex: (sync.Mutex) {
   state: (int32) 0,
   sema: (uint32) 0
  },
  name: (string) (len=1) "/",
  data: ([]uint8) <nil>,
  memDir: (*mem.DirMap)(0xc420174020)((len=1) {
   (string) (len=1) "/": (*mem.FileData)(0xc42017e0c0)(<already shown>)
  }),
  dir: (bool) true,
  mode: (os.FileMode) T---------,
  modtime: (time.Time) 2018-12-01 09:53:37.426633396 +0100 CET m=+0.005639164
 })
})
// It goes on forever

So the walkFn is called once for the file and an infinite amount of times for /. (It doesn't work with . instead of / either)

Ma124 avatar Dec 01 '18 09:12 Ma124