| 
									
										
										
										
											2024-06-13 22:21:00 +02:00
										 |  |  | //go:build darwin || freebsd || linux || solaris || windows | 
					
						
							|  |  |  | // +build darwin freebsd linux solaris windows | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 23:03:25 +02:00
										 |  |  | package fs | 
					
						
							| 
									
										
										
										
											2024-06-13 22:21:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"os" | 
					
						
							|  |  |  | 	"path/filepath" | 
					
						
							| 
									
										
										
										
											2024-06-13 22:52:31 +02:00
										 |  |  | 	"runtime" | 
					
						
							|  |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2024-06-13 22:21:00 +02:00
										 |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 23:03:25 +02:00
										 |  |  | 	"github.com/restic/restic/internal/restic" | 
					
						
							| 
									
										
										
										
											2024-06-13 22:21:00 +02:00
										 |  |  | 	rtest "github.com/restic/restic/internal/test" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 23:03:25 +02:00
										 |  |  | func setAndVerifyXattr(t *testing.T, file string, attrs []restic.ExtendedAttribute) { | 
					
						
							| 
									
										
										
										
											2024-06-13 22:52:31 +02:00
										 |  |  | 	if runtime.GOOS == "windows" { | 
					
						
							|  |  |  | 		// windows seems to convert the xattr name to upper case | 
					
						
							|  |  |  | 		for i := range attrs { | 
					
						
							|  |  |  | 			attrs[i].Name = strings.ToUpper(attrs[i].Name) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 23:03:25 +02:00
										 |  |  | 	node := &restic.Node{ | 
					
						
							| 
									
										
										
										
											2024-06-13 22:52:31 +02:00
										 |  |  | 		Type:               "file", | 
					
						
							| 
									
										
										
										
											2024-06-13 22:21:00 +02:00
										 |  |  | 		ExtendedAttributes: attrs, | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-08-26 22:35:22 +02:00
										 |  |  | 	rtest.OK(t, nodeRestoreExtendedAttributes(node, file)) | 
					
						
							| 
									
										
										
										
											2024-06-13 22:21:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 23:03:25 +02:00
										 |  |  | 	nodeActual := &restic.Node{ | 
					
						
							| 
									
										
										
										
											2024-06-13 22:52:31 +02:00
										 |  |  | 		Type: "file", | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-08-26 22:35:22 +02:00
										 |  |  | 	rtest.OK(t, nodeFillExtendedAttributes(nodeActual, file, false)) | 
					
						
							| 
									
										
										
										
											2024-06-13 22:21:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 22:35:22 +02:00
										 |  |  | 	rtest.Assert(t, nodeActual.Equals(*node), "xattr mismatch got %v expected %v", nodeActual.ExtendedAttributes, node.ExtendedAttributes) | 
					
						
							| 
									
										
										
										
											2024-06-13 22:21:00 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestOverwriteXattr(t *testing.T) { | 
					
						
							|  |  |  | 	dir := t.TempDir() | 
					
						
							|  |  |  | 	file := filepath.Join(dir, "file") | 
					
						
							|  |  |  | 	rtest.OK(t, os.WriteFile(file, []byte("hello world"), 0o600)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 23:03:25 +02:00
										 |  |  | 	setAndVerifyXattr(t, file, []restic.ExtendedAttribute{ | 
					
						
							| 
									
										
										
										
											2024-06-13 22:21:00 +02:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			Name:  "user.foo", | 
					
						
							|  |  |  | 			Value: []byte("bar"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 23:03:25 +02:00
										 |  |  | 	setAndVerifyXattr(t, file, []restic.ExtendedAttribute{ | 
					
						
							| 
									
										
										
										
											2024-06-13 22:21:00 +02:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			Name:  "user.other", | 
					
						
							|  |  |  | 			Value: []byte("some"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | } |