示例#1
0
func (t *rpcType) GetFiles(conn *srpc.Conn) error {
	defer conn.Flush()
	t.getFilesLock.Lock()
	defer t.getFilesLock.Unlock()
	encoder := gob.NewEncoder(conn)
	numFiles := 0
	for ; ; numFiles++ {
		filename, err := conn.ReadString('\n')
		if err != nil {
			return err
		}
		filename = filename[:len(filename)-1]
		if filename == "" {
			break
		}
		filename = path.Join(t.rootDir, filename)
		if err := processFilename(conn, filename, encoder); err != nil {
			return err
		}
	}
	plural := "s"
	if numFiles == 1 {
		plural = ""
	}
	t.logger.Printf("GetFiles(): %d file%s provided\n", numFiles, plural)
	return nil
}