| 
									
										
										
										
											2022-03-28 22:23:47 +02:00
										 |  |  | //go:build !windows | 
					
						
							| 
									
										
										
										
											2017-04-15 10:53:12 +02:00
										 |  |  | // +build !windows | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package fs | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-10 19:48:22 +02:00
										 |  |  | import ( | 
					
						
							|  |  |  | 	"os" | 
					
						
							| 
									
										
										
										
											2017-07-18 21:47:30 +02:00
										 |  |  | 	"syscall" | 
					
						
							| 
									
										
										
										
											2017-05-10 19:48:22 +02:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2017-04-15 10:53:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | // fixpath returns an absolute path on windows, so restic can open long file | 
					
						
							|  |  |  | // names. | 
					
						
							|  |  |  | func fixpath(name string) string { | 
					
						
							|  |  |  | 	return name | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-10 19:48:22 +02:00
										 |  |  | // TempFile creates a temporary file which has already been deleted (on | 
					
						
							|  |  |  | // supported platforms) | 
					
						
							|  |  |  | func TempFile(dir, prefix string) (f *os.File, err error) { | 
					
						
							| 
									
										
										
										
											2022-12-02 19:36:43 +01:00
										 |  |  | 	f, err = os.CreateTemp(dir, prefix) | 
					
						
							| 
									
										
										
										
											2017-05-10 19:48:22 +02:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err = os.Remove(f.Name()); err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return f, nil | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-07-18 21:47:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | // isNotSuported returns true if the error is caused by an unsupported file system feature. | 
					
						
							|  |  |  | func isNotSupported(err error) bool { | 
					
						
							|  |  |  | 	if perr, ok := err.(*os.PathError); ok && perr.Err == syscall.ENOTSUP { | 
					
						
							|  |  |  | 		return true | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Chmod changes the mode of the named file to mode. | 
					
						
							|  |  |  | func Chmod(name string, mode os.FileMode) error { | 
					
						
							|  |  |  | 	err := os.Chmod(fixpath(name), mode) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ignore the error if the FS does not support setting this mode (e.g. CIFS with gvfs on Linux) | 
					
						
							|  |  |  | 	if err != nil && isNotSupported(err) { | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return err | 
					
						
							|  |  |  | } |