Check file modification time after key handler
This commit is contained in:
		
							parent
							
								
									cd34aa2a6b
								
							
						
					
					
						commit
						9574150f2d
					
				
							
								
								
									
										10
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								main.c
									
									
									
									
									
								
							| @ -459,6 +459,7 @@ void key_handler(const char *key, unsigned int mask) | |||||||
| 	pid_t pid; | 	pid_t pid; | ||||||
| 	int retval, status, n = mode == MODE_IMAGE ? fileidx : tns.sel; | 	int retval, status, n = mode == MODE_IMAGE ? fileidx : tns.sel; | ||||||
| 	char *cmd = exec[EXEC_KEY].cmd, kstr[32]; | 	char *cmd = exec[EXEC_KEY].cmd, kstr[32]; | ||||||
|  | 	struct stat oldstat, newstat; | ||||||
| 
 | 
 | ||||||
| 	if (cmd == NULL || key == NULL) | 	if (cmd == NULL || key == NULL) | ||||||
| 		return; | 		return; | ||||||
| @ -468,6 +469,8 @@ void key_handler(const char *key, unsigned int mask) | |||||||
| 	         mask & Mod1Mask    ? "M-" : "", | 	         mask & Mod1Mask    ? "M-" : "", | ||||||
| 	         mask & ShiftMask   ? "S-" : "", key); | 	         mask & ShiftMask   ? "S-" : "", key); | ||||||
| 
 | 
 | ||||||
|  | 	stat(files[n].path, &oldstat); | ||||||
|  | 
 | ||||||
| 	if ((pid = fork()) == 0) { | 	if ((pid = fork()) == 0) { | ||||||
| 		execl(cmd, cmd, kstr, files[n].path, NULL); | 		execl(cmd, cmd, kstr, files[n].path, NULL); | ||||||
| 		warn("could not exec key handler"); | 		warn("could not exec key handler"); | ||||||
| @ -482,6 +485,13 @@ void key_handler(const char *key, unsigned int mask) | |||||||
| 	retval = WEXITSTATUS(status); | 	retval = WEXITSTATUS(status); | ||||||
| 	if (WIFEXITED(status) == 0 || retval != 0) | 	if (WIFEXITED(status) == 0 || retval != 0) | ||||||
| 		warn("key handler exited with non-zero return value: %d", retval); | 		warn("key handler exited with non-zero return value: %d", retval); | ||||||
|  | 
 | ||||||
|  | 	if (stat(files[n].path, &newstat) == 0 && | ||||||
|  | 	    memcmp(&oldstat, &newstat, sizeof(oldstat)) == 0) | ||||||
|  | 	{ | ||||||
|  | 		/* file has not changed */ | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
| 	if (mode == MODE_IMAGE) { | 	if (mode == MODE_IMAGE) { | ||||||
| 		img_close(&img, true); | 		img_close(&img, true); | ||||||
| 		load_image(fileidx); | 		load_image(fileidx); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Bert Münnich
						Bert Münnich