Trying to get a list of file names from a directory mounted on a CIFS file system. When there is a certain number of files (> 55) that are in the sequence, that is 00000.xxx through 00299.xxx, some files are not listed (for example, the file 00055.xxx may be missing). It does not matter the size of the files. They can be zero. Using the same code from the local file system works fine. Missing files seem compatible with the number of files in the directory (for example, 56 files in the directory may always be 21, while 300 files may be 55, 81, 137). In the programs below, errors are not returned.
This works on CentOS 7.4.
The golang program has been reduced to two different methods (both do not work):
Method 1:
package main
import "os"
import "fmt"
import "io/ioutil"
func main() {
directory := os.Args[1]
files, readDirError := ioutil.ReadDir(directory)
if readDirError != nil {
fmt.Printf("Error in readDir\n")
fmt.Println(readDirError)
fmt.Println("\n")
}
for x, f := range files {
fmt.Printf("%d => %s\n", x, f.Name())
}
}
Method # 2
package main
import "os"
import "fmt"
func main() {
dir, readDirError := os.Open(os.Args[1])
defer dir.Close()
if readDirError != nil {
fmt.Printf("Error in readDir\n")
fmt.Println(readDirError)
fmt.Println("\n")
}
fi, err := dir.Stat()
if err != nil {
fmt.Println(err)
return
}
if fi.IsDir() {
fis, err := dir.Readdir(-1)
if err != nil {
fmt.Println(err)
return
}
for _, fileinfo := range fis {
fmt.Printf("%s\n", fileinfo.Name())
}
}
}
Created a C program that did the same, and it works every time, that is, it lists all the files in the directory. Thus, this does not seem to be a problem with getting all the information from the file system.
#include <dirent.h>
#include <stdio.h>
int main(int c, char **argv)
{
DIR *d;
struct dirent *dir;
d = opendir(argv[1]);
if (d)
{
while ((dir = readdir(d)) != NULL)
{
printf("%s\n", dir->d_name);
}
closedir(d);
}
return(0);
}
Is there any clue on what might be the problem? At this point, I think we might need to wrap the C function to get the correct list.
By the way, the files in the directory all have the same permissions, none of them are symbolic or hard, everything looks fine from the ls -l command in the terminal window.