Exemplo n.º 1
0
func Read(path string) (string, TargetType, error) {
	ptr, err := syscall.UTF16PtrFromString(path)
	if err != nil {
		return "", TargetUnknown, err
	}
	handle, err := syscall.CreateFile(ptr, 0, syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE, nil, syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS|Win32FileFlagOpenReparsePoint, 0)
	if err != nil || handle == syscall.InvalidHandle {
		return "", TargetUnknown, err
	}
	defer syscall.Close(handle)
	var ret uint16
	var data reparseData

	r1, _, err := syscall.Syscall9(procDeviceIoControl.Addr(), 8, uintptr(handle), Win32FsctlGetReparsePoint, 0, 0, uintptr(unsafe.Pointer(&data)), unsafe.Sizeof(data), uintptr(unsafe.Pointer(&ret)), 0, 0)
	if r1 == 0 {
		return "", TargetUnknown, err
	}

	tt := TargetUnknown
	if attr, err := syscall.GetFileAttributes(ptr); err == nil {
		if attr&syscall.FILE_ATTRIBUTE_DIRECTORY != 0 {
			tt = TargetDirectory
		} else {
			tt = TargetFile
		}
	}

	return osutil.NormalizedFilename(data.PrintName()), tt, nil
}
Exemplo n.º 2
0
func (s *FileSet) GetGlobalTruncated(file string) (FileInfoTruncated, bool) {
	fi, ok := s.db.getGlobal([]byte(s.folder), []byte(osutil.NormalizedFilename(file)), true)
	if !ok {
		return FileInfoTruncated{}, false
	}
	f := fi.(FileInfoTruncated)
	f.Name = osutil.NativeFilename(f.Name)
	return f, true
}
Exemplo n.º 3
0
func (s *FileSet) GetGlobal(file string) (protocol.FileInfo, bool) {
	fi, ok := s.db.getGlobal([]byte(s.folder), []byte(osutil.NormalizedFilename(file)), false)
	if !ok {
		return protocol.FileInfo{}, false
	}
	f := fi.(protocol.FileInfo)
	f.Name = osutil.NativeFilename(f.Name)
	return f, true
}
Exemplo n.º 4
0
func Read(path string) (string, TargetType, error) {
	tt := TargetUnknown
	if stat, err := os.Stat(path); err == nil {
		if stat.IsDir() {
			tt = TargetDirectory
		} else {
			tt = TargetFile
		}
	}
	path, err := os.Readlink(path)

	return osutil.NormalizedFilename(path), tt, err
}
Exemplo n.º 5
0
func normalizeFilenames(fs []protocol.FileInfo) {
	for i := range fs {
		fs[i].Name = osutil.NormalizedFilename(fs[i].Name)
	}
}
Exemplo n.º 6
0
func (s *FileSet) Availability(file string) []protocol.DeviceID {
	return s.db.availability([]byte(s.folder), []byte(osutil.NormalizedFilename(file)))
}
Exemplo n.º 7
0
func (s *FileSet) Get(device protocol.DeviceID, file string) (protocol.FileInfo, bool) {
	f, ok := s.db.getFile([]byte(s.folder), device[:], []byte(osutil.NormalizedFilename(file)))
	f.Name = osutil.NativeFilename(f.Name)
	return f, ok
}
Exemplo n.º 8
0
func (s *FileSet) WithPrefixedGlobalTruncated(prefix string, fn Iterator) {
	l.Debugf("%s WithPrefixedGlobalTruncated()", s.folder, prefix)
	s.db.withGlobal([]byte(s.folder), []byte(osutil.NormalizedFilename(prefix)), true, nativeFileIterator(fn))
}