14 #include <WINGs/WINGs.h>
15 #include <WINGs/WUtil.h>
21 static Bool DISPLAY_HIDDEN_FILES
= False
;
22 static Bool SORT_TOGGLE
= True
;
24 static int copy(ino_t
*inodes
, int n_inodes
, char *oldpath
, char *newpath
);
25 static int copyfile(char *oldpath
, char *newpath
);
26 static int copydir(ino_t
*inodes
, int n_inodes
, struct stat
*oldstats
,
27 char *oldpath
, char *newpath
);
30 ** Here's an example of how to sort a singly-linked list. I think it
31 ** can be modified to sort a doubly-linked list, but it would get a bit
32 ** more complicated. Note that this is a recursive method, but the
33 ** recursion depth is limited to be proportional to the base 2 log of
34 ** the length of the list, so it won't "run away" and blow the stack.
36 ** 10/21/93 rdg Fixed bug -- function was okay, but called incorrectly.
37 ** linked list sort -- public domain by Ray Gardner 5/90
41 Taken from the code snippet website (sorry no URL)
42 Functions modified on 98/10/14 by George Clernon (clernong@tinet.ie)
43 for Workplace.app list type.
46 /* returns < 0 if *p sorts lower than *q */
47 int keycmp (FileInfo
*p
, FileInfo
*q
)
49 if( FSGetIntegerForName("SortOrder") )
50 return strcasecmp(p
->name
, q
->name
);
52 return strcasecmp(q
->name
, p
->name
);
55 /* merge 2 lists under dummy head item */
56 FileInfo
*lmerge (FileInfo
*p
, FileInfo
*q
)
60 for ( r
= &head
; p
&& q
; )
62 if ( keycmp(p
, q
) < 0 )
73 r
->next
= (p
? p
: q
);
78 /* split list into 2 parts, sort each recursively, merge */
79 FileInfo
*lsort (FileInfo
*p
)
86 for ( r
= q
->next
; r
&& (r
= r
->next
) != NULL
; r
= r
->next
)
93 p
= lmerge(lsort(r
), lsort(p
));
98 /* FileInfo *GetDirList(char *path) */
100 /* char *fullPath; */
102 /* FileInfo *fileList; */
103 /* struct dirent *dirent; */
106 /* fullPath = wexpandpath(path); */
108 /* dir = opendir(fullPath); */
111 /* printf("Unable to open dir: %s\n", path); */
115 /* fileList = (FileInfo *) wmalloc(sizeof(FileInfo)); */
116 /* fileList->next = NULL; */
117 /* fileList->name = NULL; */
118 /* fileList->fileType = NORMAL; */
119 /* fileList->imgName = NULL; */
120 /* fileList->abbrev = NULL; */
121 /* top = fileList; */
123 /* dirent = readdir(dir); */
126 /* GetFileInfo(fullPath, dirent->d_name, fileList); */
128 /* dirent = readdir(dir); */
132 /* fileList->next = (FileInfo *) wmalloc(sizeof(FileInfo)); */
133 /* fileList = fileList->next; */
134 /* fileList->next = NULL; */
141 /* free(fullPath); */
143 /* return lsort(top); */
146 FileInfo
*GetDirList(char *path
)
149 Bool dirFirst
= False
;
150 char *fullPath
= NULL
;
151 FileInfo
*topDir
= NULL
;
152 FileInfo
*topFile
= NULL
;
153 FileInfo
*dirList
= NULL
;
154 FileInfo
*fileList
= NULL
;
155 FileInfo
*fileInfo
= NULL
;
156 struct dirent
*dirent
= NULL
;
159 fullPath
= wexpandpath(path
);
161 dir
= opendir(fullPath
);
164 /* printf("Unable to open dir: %s\n", path); */
168 if(FSGetIntegerForName("SortDisplay") == 0)
170 else if(FSGetIntegerForName("SortDisplay") == 2)
173 while( (dirent
= readdir(dir
)) != NULL
)
175 fileInfo
= FSCreateFileInfo();
177 GetFileInfo(fullPath
, dirent
->d_name
, fileInfo
);
179 if( !mixed
&& isDirectory(fileInfo
->fileType
) )
183 dirList
->next
= fileInfo
;
184 dirList
= dirList
->next
;
196 fileList
->next
= fileInfo
;
197 fileList
= fileList
->next
;
213 fileList
= lsort(topFile
);
215 dirList
= lsort(topDir
);
222 while(dirList
->next
!= NULL
)
223 dirList
= dirList
->next
;
224 dirList
->next
= fileList
;
234 while(fileList
->next
!= NULL
)
235 fileList
= fileList
->next
;
236 fileList
->next
= dirList
;
245 void GetFileInfo(char* path
, char *name
, FileInfo
* fileInfo
)
252 st
= (struct stat
*) wmalloc(sizeof(struct stat
));
254 /* make abosolute pathname */
255 pathname
= (char *) wmalloc(strlen(path
)+strlen(name
)+1);
256 strcpy(pathname
, path
);
257 pathname
= strcat(pathname
, name
);
259 /* get information of a file represented by pathname */
260 if (stat(pathname
, st
) == -1)
261 wwarning(_("%s GetFileInfo %d: Stat Error for %s\n"),
262 __FILE__
, __LINE__
, pathname
);
264 if(strcmp("/", pathname
) == 0)
266 fileInfo
->fileType
= ROOT
;
267 fileName
= FSNodeName();
269 else if(strcmp(FSGetHomeDir(), pathname
) == 0) {
270 fileInfo
->fileType
= HOME
;
271 fileName
= (char *) wmalloc(strlen(name
)+1);
272 strcpy(fileName
, name
);
276 if(S_ISDIR(st
->st_mode
))
277 fileInfo
->fileType
= DIRECTORY
;
279 fileInfo
->fileType
= NORMAL
;
281 fileName
= (char *) wmalloc(strlen(name
)+1);
282 strcpy(fileName
, name
);
285 dirPath
= (char *) wmalloc(strlen(path
)+1);
286 strcpy(dirPath
, path
);
288 fileInfo
->name
= fileName
;
289 fileInfo
->path
= dirPath
;
291 if(fileInfo
->fileType
== ROOT
)
292 fileInfo
->extn
= wstrdup("ROOT");
294 fileInfo
->extn
= wstrdup(GetFileExtn(fileInfo
->name
));
296 fileInfo
->imgName
= GetFileImgName(GetFileExtn(fileName
),
298 fileInfo
->abbrev
= GetFileAbbrev(fileName
);
318 RemoveFileExtension(char* filename
)
324 tmp
= strrchr(filename
, '.');
326 len
= strlen(filename
)-strlen(tmp
);
328 str
= (char *) wmalloc(len
+1);
329 strncpy(str
, filename
, len
);
336 GetFileExtn(char *filename
)
340 if(FSStringMatch("*.tar.gz", filename
))
341 return wstrdup(".tar.gz");
343 extn
= strrchr(filename
, '.');
347 /* extn = (char *) wmalloc(strlen(filename)+1); */
348 /* strcpy(extn, filename); */
349 extn
= wstrdup(filename
);
356 char *GetFileAbbrev(char *fileName
)
361 abbrev
= (char *) wmalloc(strlen(fileName
)+1);
363 if (strlen(fileName
)>19)
365 strncpy(abbrev
, fileName
, 16);
367 strcat(abbrev
, "...");
372 strcpy(abbrev
, fileName
);
378 char* GetFileImgName(char *fileName
, enum FileType fileType
)
380 /*WMPropList* dict, value = NULL;*/
386 * I'm not sure what should happen here
387 * Cos the event should really arise.
388 * Need to improve error handling in functions
392 return wstrdup(DEFAULT_STR
);
396 extn
= wstrdup("ROOT");
398 extn
= wstrdup(GetFileExtn(fileName
));
400 name
= FSGetStringForNameKey(extn
, "icon");
404 if(fileType
== DIRECTORY
)
405 name
= FSGetStringForName(DIR_STR
);
406 else if(fileType
== ROOT
)
407 name
= FSGetStringForNameKey(ROOT_STR
, "icon");
408 else if(fileType
== HOME
)
409 name
= FSGetStringForName(HOME_STR
);
411 name
= FSGetStringForName(DEFAULT_STR
);
414 icon
= LocateImage(name
);
423 return wstrdup(DEFAULT_STR
);
425 /* dict = PLGetDictionaryEntry(filesDB, PLMakeString(extn)); */
426 /* if(dict && PLIsDictionary(dict)) */
428 /* value = PLGetDictionaryEntry(dict, PLMakeString("icon")); */
431 /* if(value == NULL) */
433 /* if(fileType == DIRECTORY) */
434 /* value = PLGetDictionaryEntry(filesDB, PLMakeString(DIR_STR)); */
435 /* else if(fileType == ROOT) */
436 /* value = PLGetDictionaryEntry(filesDB, PLMakeString(ROOT_STR)); */
437 /* else if(fileType == HOME) */
438 /* value = PLGetDictionaryEntry(filesDB, PLMakeString(HOME_STR)); */
441 /* value = PLGetDictionaryEntry(filesDB, PLMakeString(DEFAULT_STR)); */
448 /* No Icons at all!! */
449 /* if(value == NULL) */
451 /* return DEFAULT_STR; */
454 /* return PLGetString(value); */
459 GetNameFromPathname(char* pathname
)
463 str
= strrchr(pathname
, '/');
469 char* GetPathFromPathname(char* pathname
)
476 lenTot
= strlen(pathname
);
477 lenName
= strlen(GetNameFromPathname(pathname
));
478 lenPath
= lenTot
- lenName
;
480 path
= (char *) wmalloc(lenPath
+1);
481 strncpy(path
, pathname
, lenPath
);
482 path
[lenPath
] = '\0';
487 char* GetPathnameFromPathName(char* path
, char *name
)
492 len
= strlen(GetNameFromPathname(path
));
495 pathname
= (char *)wmalloc(strlen(path
)+strlen(name
)+2);
496 strcpy(pathname
, path
);
497 strcat(pathname
, "/");
498 strcat(pathname
, name
);
502 pathname
= (char *)wmalloc(strlen(path
)+strlen(name
)+1);
503 strcpy(pathname
, path
);
504 strcat(pathname
, name
);
510 Bool
isDirectory(enum FileType fileType
)
513 if(fileType
== DIRECTORY
|| fileType
== ROOT
|| fileType
== HOME
)
520 DisplayFile(char *str
, char *filter
, FileType fileType
)
523 /* if(str[0] != '.') */
527 /* else if(DISPLAY_HIDDEN_FILES) */
529 /* if(str[1] != '.' && str[1] != '\0') */
536 if( !strcmp(".", str
) || !strcmp("..", str
) )
538 else if( filter
&& !isDirectory(fileType
) )
539 if( !FSStringMatch(filter
, str
) )
543 return FSGetIntegerForName("DisplayDotFiles");/* DISPLAY_HIDDEN_FILES; */
549 FSToggleDisplayHiddenFiles()
551 /* DISPLAY_HIDDEN_FILES = !DISPLAY_HIDDEN_FILES; */
552 /* if( FSGetIntegerForName("DisplayDotFiles") )
553 FSSetIntegerForName("DisplayDotFiles", 0);
555 FSSetIntegerForName("DisplayDotFiles", 1);*/
556 FSSetIntegerForName("DisplayDotFiles",
557 !FSGetIntegerForName("DisplayDotFiles"));
563 /* SORT_TOGGLE = !SORT_TOGGLE; */
564 /* if( FSGetIntegerForName("SortOrder") )
565 FSSetIntegerForName("SortOrder", 0);
567 FSSetIntegerForName("SortOrder", 1);*/
568 FSSetIntegerForName("SortOrder",
569 !FSGetIntegerForName("SortOrder"));
578 fileInfo
= (FileInfo
*) wmalloc(sizeof(FileInfo
));
579 memset(fileInfo
, 0, sizeof(FileInfo
));
580 /* fileInfo->next = NULL; */
581 /* fileInfo->name = NULL; */
582 /* fileInfo->path = NULL; */
583 fileInfo
->fileType
= NORMAL
;
584 fileInfo
->imgName
= GetFileImgName(NULL_STR
, NORMAL
);
585 /* fileInfo->abbrev = NULL; */
586 /* fileInfo->extn = NULL; */
587 /* fileInfo->st = NULL; */
595 FSCopyFileInfo(FileInfo
*src
, FileInfo
*dest
)
598 if(src
== NULL
|| dest
== NULL
)
603 dest
->name
= (char *) wrealloc(dest
->name
, strlen(src
->name
)+1);
604 strcpy(dest
->name
, src
->name
);
611 dest
->path
=(char *) wrealloc(dest
->path
, strlen(src
->path
)+1);
612 strcpy(dest
->path
, src
->path
);
619 dest
->extn
= (char *) wrealloc(dest
->extn
, strlen(src
->extn
)+1);
620 strcpy(dest
->extn
, src
->extn
);
627 dest
->abbrev
= (char *) wrealloc(dest
->abbrev
, strlen(src
->abbrev
)+1);
628 strcpy(dest
->abbrev
, src
->abbrev
);
635 dest
->imgName
= (char*)wrealloc(dest
->imgName
, strlen(src
->imgName
)+1);
636 strcpy(dest
->imgName
, src
->imgName
);
639 dest
->imgName
= NULL
;
641 dest
->fileType
= src
->fileType
;
644 * Not sure if I really want to do this!!!
645 * It should be done though, I think I'll call back later
649 /* dest->next = FSCreateFileInfo(); */
650 /* FSCopyFileInfo(src->next, dest->next); */
656 FSFreeFileInfo(FileInfo
*fileInfo
)
663 free(fileInfo
->name
);
664 fileInfo
->name
= NULL
;
668 free(fileInfo
->path
);
669 fileInfo
->path
= NULL
;
671 if(fileInfo
->imgName
)
673 free(fileInfo
->imgName
);
674 fileInfo
->imgName
= NULL
;
678 free(fileInfo
->extn
);
679 fileInfo
->extn
= NULL
;
683 free(fileInfo
->abbrev
);
684 fileInfo
->abbrev
= NULL
;
693 FSFreeFileInfo(fileInfo
->next
);
699 /* check whether a file exists */
701 FSFileExists(char *path
)
705 return (!lstat(path
, &stats
));
709 FSGetFileInfo(char* pathname
)
713 FileInfo
*fileInfo
= FSCreateFileInfo();
715 name
= GetNameFromPathname(pathname
);
716 path
= GetPathFromPathname(pathname
);
718 GetFileInfo(path
, name
, fileInfo
);
723 /* create a new directory */
725 FSCreateNewFile(char *path
, mode_t mode
)
727 int file
= open(path
, O_WRONLY
|O_CREAT
|O_EXCL
, mode
);
729 if (file
== -1 || close(file
))
735 /* create a new file */
737 FSCreateNewDirectory(char *path
, mode_t mode
)
739 return mkdir(path
, mode
);
741 /* if (mkdir(path, mode)) */
745 /* sprintf(s, "Error creating folder %s:", path); */
746 /* FSErrorDialog("File Operation Error", s); */
750 /*-------------------------------------------------------------------------*/
752 /* recursive copy operation */
755 FSRCopy(char *oldpath
, char *newpath
)
757 return copy((ino_t
*)NULL
, 0, oldpath
, newpath
);
761 copyfile(char *oldpath
, char *newpath
)
764 int src
= -1, dest
= -1, n
, errno_ret
;
767 if ((src
= open(oldpath
, O_RDONLY
)) == -1 || stat(oldpath
, &stats
))
769 else if ((dest
= creat(newpath
, stats
.st_mode
)) == -1)
772 while ( (n
= read(src
, buf
, BUFSIZ
)) != 0)
773 if ( n
== -1 || write(dest
, buf
, n
) != n
)
786 if (src
!= -1) close(src
);
787 if (dest
!= -1) close(dest
);
793 copydir(ino_t
*inodes
, int n_inodes
, struct stat
*oldstats
,
794 char *oldpath
, char *newpath
)
797 struct dirent
*entry
;
798 int i
, ol
= strlen(oldpath
), nl
= strlen(newpath
);
799 struct stat newstats
;
800 mode_t umask
= FSGetUMask();
802 for (i
= n_inodes
-1; i
>= 0; i
--)
803 if (inodes
[i
] == oldstats
->st_ino
)
809 if ((mkdir(newpath
, umask
& 0777) < 0 && errno
!= EEXIST
) ||
810 lstat(newpath
, &newstats
) ||
811 !(dir
= opendir(oldpath
)))
814 inodes
= (ino_t
*) wrealloc(inodes
, (n_inodes
+1)*sizeof(ino_t
));
815 inodes
[n_inodes
++] = newstats
.st_ino
;
817 for(i
= 0; (entry
= readdir(dir
)); i
++)
818 if (entry
->d_name
[0] != '.' || (entry
->d_name
[1] != '\0'
819 && (entry
->d_name
[1] != '.' ||
820 entry
->d_name
[2] != '\0')))
822 int ol1
= ol
, nl1
= nl
, l
= strlen(entry
->d_name
);
823 char *oldpath1
= (char *)alloca(ol1
+l
+2);
824 char *newpath1
= (char *)alloca(nl1
+l
+2);
826 strcpy(oldpath1
, oldpath
);
827 strcpy(newpath1
, newpath
);
828 if (oldpath1
[ol1
-1] != '/')
829 oldpath1
[ol1
++] = '/';
830 if (newpath1
[nl1
-1] != '/')
831 newpath1
[nl1
++] = '/';
832 strcpy(oldpath1
+ol1
, entry
->d_name
);
833 strcpy(newpath1
+nl1
, entry
->d_name
);
834 if (copy(inodes
, n_inodes
, oldpath1
, newpath1
))
836 /* take care of recursive errors */
838 sprintf(s
, _("Error copying %s:"), oldpath1
);
839 FSErrorDialog(_("File Operation Error"), s
);
843 inodes
= (ino_t
*) wrealloc(inodes
, (n_inodes
-1)*sizeof(ino_t
));
844 return closedir(dir
);
848 copy(ino_t
*inodes
, int n_inodes
, char *oldpath
, char *newpath
)
851 mode_t umask
= FSGetUMask();
853 if (lstat(oldpath
, &stats
))
856 /* Directory: copy recursively */
857 if (S_ISDIR(stats
.st_mode
))
858 return copydir(inodes
, n_inodes
, &stats
, oldpath
, newpath
);
860 /* Regular file: copy block by block */
861 else if (S_ISREG(stats
.st_mode
))
862 return copyfile(oldpath
, newpath
);
864 /* Fifo: make a new one */
865 else if (S_ISFIFO(stats
.st_mode
))
866 return mkfifo(newpath
, umask
& 0666);
868 /* Device: make a new one */
869 else if (S_ISBLK(stats
.st_mode
) || S_ISCHR(stats
.st_mode
) ||
870 S_ISSOCK(stats
.st_mode
))
871 return mknod(newpath
, umask
& 0666, stats
.st_rdev
);
873 /* Symbolic link: make a new one */
874 else if (S_ISLNK(stats
.st_mode
))
877 int l
= readlink(oldpath
, lnk
, MAX_LEN
);
882 return(symlink(lnk
, newpath
));
885 /* This shouldn't happen */
889 sprintf(s
, _("Unrecognized File type: %s"), oldpath
);
890 FSErrorDialog(_("File Operation Error"), s
);
896 /*-------------------------------------------------------------------------*/
898 /* recursive delete */
905 if (lstat(path
, &stats
))
908 if (S_ISDIR(stats
.st_mode
))
911 struct dirent
*entry
;
912 int i
, pl
= strlen(path
);
914 if (!(dir
= opendir(path
)))
917 for(i
= 0; (entry
= readdir(dir
)); i
++)
918 if (entry
->d_name
[0] != '.' || (entry
->d_name
[1] != '\0'
919 && (entry
->d_name
[1] != '.' ||
920 entry
->d_name
[2] != '\0')))
922 int pl1
= pl
, l
= strlen(entry
->d_name
);
923 char *path1
= (char *)alloca(pl1
+l
+2);
926 if (path1
[pl1
-1] != '/')
928 strcpy(path1
+pl1
, entry
->d_name
);
930 /* take care of recursive errors */
932 sprintf(s
, _("Error deleting %s:"), path
);
933 FSErrorDialog(_("File Operation Error"), s
);
947 FSCopy(FileInfo
*src
, FileInfo
*dest
)
950 int i
, toi
, n_copied
= 0;
954 from
= GetPathnameFromPathName(src
->path
, src
->name
);
955 strcpy(to
, GetPathnameFromPathName(dest
->path
, dest
->name
));
957 if (access(to
, W_OK
) && isDirectory(dest
->fileType
))
961 sprintf(s
, _("No write access to %s"), to
);
962 FSErrorDialog(_("File Operation Error"), s
);
969 if target exists and is a directory, copy the source
972 if(!stat(to
, &stats
) && S_ISDIR(stats
.st_mode
))
974 if (!strcmp(from
, to
))
976 FSErrorDialog(_("File Operation Error"),
977 _("Copy: Source and destination are identical"));
991 Should do a loop here that goes through each element
992 of the FileInfo list, checks and copies it
994 strcpy(to
+toi
, src
->name
);
995 if(FSFileExists(to
) /* && resources.confirm_overwrite */)
998 sprintf(s
, _("Copy: file %s already exists at destination"),
1000 if(FSConfirmationDialog(_("Overwrite?"), s
))
1008 if(FSRCopy(from
, to
))
1011 sprintf(s
, _("Error copying %s:"), from
);
1012 FSErrorDialog(_("File Operation Error"), s
);
1019 otherwise only a single file may be selected;
1020 copy it to the target file
1022 /* else if (popups.fw->n_selections > 1) */
1024 /* error("Copy: target for multiple files", "must be a folder"); */
1031 if(!stat(from
, &stats1
) && S_ISDIR(stats1
.st_mode
))
1033 FSErrorDialog(_("File Operation Error"),
1034 _("Cannot copy a directory to a file"));
1040 if (!lstat(to
, &stats
) && !lstat(from
, &stats1
) &&
1041 stats
.st_ino
== stats1
.st_ino
)
1043 FSErrorDialog(_("File Operation Error"),
1044 _("Copy: Source and destination are identical"));
1050 if (FSFileExists(to
) /* && resources.confirm_overwrite */)
1053 sprintf(s
, _("Copy: file %s already exists"), to
);
1054 if(FSConfirmationDialog(_("Overwrite?"), s
))
1062 if (FSRCopy(from
, to
))
1065 sprintf(s
, _("Error copying %s:"), from
);
1066 FSErrorDialog(_("File Operation Error"), s
);
1073 FSUpdateFileView(FileCopy
, src
, dest
);
1080 FSDelete(FileInfo
*item
)
1084 int i
, n_deleted
= 0;
1086 itemName
= GetPathnameFromPathName(item
->path
, item
->name
);
1088 if (isDirectory(item
->fileType
))
1089 if (!strcmp(item
->name
, ".") || !strcmp(item
->name
, ".."))
1091 FSErrorDialog(_("File Operation Error"), _("Cannot delete . or .."));
1096 /* else if (resources.confirm_delete_folder) */
1099 /* sprintf(s, "Do you REALLY wish to delete folder %s"\ */
1100 /* "and ALL items contained in it?", itemName); */
1102 sprintf(s
, _("Do you REALLY wish to delete %s"), itemName
);
1104 if(FSConfirmationDialog(_("File Operation"), s
))
1112 if (FSRDel(itemName
))
1114 sprintf(s
, _("Error deleting %s:"), itemName
);
1115 FSErrorDialog(_("File Operation Error"), s
);
1121 FSUpdateFileView(FileDelete
, item
, NULL
);
1128 FSMove(FileInfo
*src
, FileInfo
*dest
)
1131 int i
, toi
, n_moved
= 0;
1135 from
= GetPathnameFromPathName(src
->path
, src
->name
);
1136 strcpy(to
, GetPathnameFromPathName(dest
->path
, dest
->name
));
1138 if(access(to
, W_OK
) && isDirectory(dest
->fileType
))
1142 sprintf(s
, _("No write access to %s"), to
);
1143 FSErrorDialog(_("File Operation Error"), s
);
1150 if target exists and is a directory, move the source
1153 if(!stat(to
, &stats
) && S_ISDIR(stats
.st_mode
))
1155 if (!strcmp(from
, to
))
1157 FSErrorDialog(_("File Operation Error"),
1158 _("Move: Source and destination are identical"));
1165 if(to
[toi
-1] != '/')
1172 Should do a loop here that goes through each element
1173 of the FileInfo list, checks and moves it
1175 strcpy(to
+toi
, src
->name
);
1176 if(FSFileExists(to
) /* && resources.confirm_overwrite */)
1179 sprintf(s
, _("Move: file %s already exists at destination"),
1181 if(FSConfirmationDialog(_("Overwrite?"), s
))
1189 if(rename(from
, to
))
1192 sprintf(s
, _("Error copying %s:"), from
);
1193 FSErrorDialog(_("File Operation Error"), s
);
1201 otherwise only a single file may be selected;
1202 copy it to the target file
1204 /* else if (popups.fw->n_selections > 1) */
1206 /* error("Copy: target for multiple files", "must be a folder"); */
1213 if(!stat(from
, &stats1
) && S_ISDIR(stats1
.st_mode
))
1215 FSErrorDialog(_("File Operation Error"),
1216 _("Cannot move a directory to a file"));
1222 if (!lstat(to
, &stats
) && !lstat(from
, &stats1
) &&
1223 stats
.st_ino
== stats1
.st_ino
)
1225 FSErrorDialog(_("File Operation Error"),
1226 _("Move: Source and destination are identical"));
1232 if (FSFileExists(to
) /* && resources.confirm_overwrite */)
1235 sprintf(s
, _("Move: file %s already exists"), to
);
1236 if(FSConfirmationDialog(_("Overwrite?"), s
))
1244 if (rename(from
, to
))
1247 sprintf(s
, _("Error renaming %s:"), from
);
1248 FSErrorDialog(_("File Operation Error"), s
);
1255 FSUpdateFileView(FileMove
, src
, dest
);
1262 FSRename(FileInfo
*src
, FileInfo
*dest
)
1266 int i
, toi
, n_renamed
= 0;
1270 from
= GetPathnameFromPathName(src
->path
, src
->name
);
1271 to
= GetPathnameFromPathName(dest
->path
, dest
->name
);
1274 if (!lstat(to
, &stats
) && !lstat(from
, &stats1
) &&
1275 stats
.st_ino
== stats1
.st_ino
)
1277 FSErrorDialog(_("File Operation Error"),
1278 _("Rename: Source and destination are identical"));
1286 if (FSFileExists(to
) /* && resources.confirm_overwrite */)
1289 sprintf(s
, _("Rename: file %s already exists"), to
);
1290 if(FSConfirmationDialog(_("Overwrite?"), s
))
1300 if (rename(from
, to
))
1303 sprintf(s
, _("Error renaming %s:"), from
);
1304 FSErrorDialog(_("File Operation Error"), s
);
1310 FSUpdateFileView(FileRename
, src
, dest
);
1319 FSLink(FileInfo
*src
, FileInfo
*dest
)
1322 int i
, toi
, n_linked
= 0;
1326 from
= GetPathnameFromPathName(src
->path
, src
->name
);
1327 to
= GetPathnameFromPathName(dest
->path
, dest
->name
);
1330 if target exists and is a directory,
1331 link the source into that directory
1333 if(!stat(to
, &stats
) && S_ISDIR(stats
.st_mode
))
1335 if (!strcmp(from
, to
))
1337 FSErrorDialog(_("File Operation Error"),
1338 _("Copy: Source and destination are identical"));
1347 if(to
[toi
-1] != '/')
1354 Should do a loop here that goes through each element
1355 of the FileInfo list, checks and copies it
1357 strcpy(to
+toi
, src
->name
);
1358 if(FSFileExists(to
) /* && resources.confirm_overwrite */)
1361 sprintf(s
, _("Link: file %s already exists at destination"),
1363 if(FSConfirmationDialog(_("Overwrite?"), s
))
1373 if (symlink(from
,to
))
1376 sprintf(s
, _("Error linking %s to %s"), from
, to
);
1377 FSErrorDialog(_("File Operation Error"), s
);
1382 /* otherwise only a single file may be selected;
1383 link it to the target file */
1384 /* else if (popups.fw->n_selections > 1) { */
1386 /* error("Link: target for multiple files", "must be a folder"); */
1394 if (!lstat(to
, &stats
) && !lstat(from
, &stats1
) &&
1395 stats
.st_ino
== stats1
.st_ino
)
1397 FSErrorDialog(_("File Operation Error"),
1398 _("Link: Source and destination are identical"));
1406 if (FSFileExists(to
) /* && resources.confirm_overwrite */)
1409 sprintf(s
, _("Link: file %s already exists"), to
);
1410 if(FSConfirmationDialog(_("Overwrite?"), s
))
1420 if(symlink(from
,to
))
1423 sprintf(s
, _("Error linking %s to %s"), from
, to
);
1424 FSErrorDialog(_("File Operation Error"), s
);
1431 FSUpdateFileView(FileLink
, src
, dest
);