Esempio n. 1
0
func Read(path string) (string, uint32, error) {
	ptr, err := syscall.UTF16PtrFromString(path)
	if err != nil {
		return "", protocol.FlagSymlinkMissingTarget, 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 "", protocol.FlagSymlinkMissingTarget, 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 "", protocol.FlagSymlinkMissingTarget, err
	}

	var flags uint32
	attr, err := syscall.GetFileAttributes(ptr)
	if err != nil {
		flags = protocol.FlagSymlinkMissingTarget
	} else if attr&syscall.FILE_ATTRIBUTE_DIRECTORY != 0 {
		flags = protocol.FlagDirectory
	}

	return osutil.NormalizedFilename(data.PrintName()), flags, nil
}
func (BasicFilesystem) ReadSymlink(path string) (string, LinkTargetType, error) {
	ptr, err := syscall.UTF16PtrFromString(path)
	if err != nil {
		return "", LinkTargetUnknown, 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 "", LinkTargetUnknown, 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 "", LinkTargetUnknown, err
	}

	tt := LinkTargetUnknown
	if attr, err := syscall.GetFileAttributes(ptr); err == nil {
		if attr&syscall.FILE_ATTRIBUTE_DIRECTORY != 0 {
			tt = LinkTargetDirectory
		} else {
			tt = LinkTargetFile
		}
	}

	return osutil.NormalizedFilename(data.printName()), tt, nil
}
Esempio n. 3
0
func (s *FileSet) GetGlobalTruncated(file string) (FileInfoTruncated, bool) {
	fi, ok := ldbGetGlobal(s.db, []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
}
Esempio n. 4
0
func (s *FileSet) GetGlobal(file string) (protocol.FileInfo, bool) {
	fi, ok := ldbGetGlobal(s.db, []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
}
Esempio n. 5
0
func Read(path string) (string, uint32, error) {
	var mode uint32
	stat, err := os.Stat(path)
	if err != nil {
		mode = protocol.FlagSymlinkMissingTarget
	} else if stat.IsDir() {
		mode = protocol.FlagDirectory
	}
	path, err = os.Readlink(path)

	return osutil.NormalizedFilename(path), mode, err
}
Esempio n. 6
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
}
Esempio n. 7
0
func normalizeFilenames(fs []protocol.FileInfo) {
	for i := range fs {
		fs[i].Name = osutil.NormalizedFilename(fs[i].Name)
	}
}
Esempio n. 8
0
func (s *FileSet) Availability(file string) []protocol.DeviceID {
	return ldbAvailability(s.db, []byte(s.folder), []byte(osutil.NormalizedFilename(file)))
}
Esempio n. 9
0
func (s *FileSet) Get(device protocol.DeviceID, file string) (protocol.FileInfo, bool) {
	f, ok := ldbGet(s.db, []byte(s.folder), device[:], []byte(osutil.NormalizedFilename(file)))
	f.Name = osutil.NativeFilename(f.Name)
	return f, ok
}
Esempio n. 10
0
func (s *FileSet) WithPrefixedGlobalTruncated(prefix string, fn Iterator) {
	if debug {
		l.Debugf("%s WithPrefixedGlobalTruncated()", s.folder, prefix)
	}
	ldbWithGlobal(s.db, []byte(s.folder), []byte(osutil.NormalizedFilename(prefix)), true, nativeFileIterator(fn))
}
Esempio n. 11
0
func (s *FileSet) WithPrefixedHaveTruncated(device protocol.DeviceID, prefix string, fn Iterator) {
	l.Debugf("%s WithPrefixedHaveTruncated(%v)", s.folder, device)
	s.db.withHave([]byte(s.folder), device[:], []byte(osutil.NormalizedFilename(prefix)), true, nativeFileIterator(fn))
}