"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "sync.c" between
jpilot-1.8.2.tar.gz and jpilot-2_0_1.tar.gz

About: J-Pilot is a desktop organizer application for Palm Pilot (PalmOS) devices. Ported to GTK3.

sync.c  (jpilot-1.8.2):sync.c  (jpilot-2_0_1)
skipping to change at line 658 skipping to change at line 658
} }
static int sync_rotate_backups(const int num_backups) static int sync_rotate_backups(const int num_backups)
{ {
DIR *dir; DIR *dir;
struct dirent *dirent; struct dirent *dirent;
char home_dir[FILENAME_MAX]; char home_dir[FILENAME_MAX];
char full_name[FILENAME_MAX]; char full_name[FILENAME_MAX];
char full_newdir[FILENAME_MAX]; char full_newdir[FILENAME_MAX];
char full_backup[FILENAME_MAX]; char full_backup[FILENAME_MAX];
char full_oldest[FILENAME_MAX]; char full_oldest[FILENAME_MAX + 22];
char full_src[FILENAME_MAX]; char full_src[FILENAME_MAX];
char full_dest[FILENAME_MAX]; char full_dest[FILENAME_MAX];
int r; int r;
int count, safety; int count, safety;
char oldest[20]; char oldest[20];
char newest[20]; char newest[20];
char newdir[20]; char newdir[20];
time_t ltime; time_t ltime;
struct tm *now; struct tm *now;
skipping to change at line 1164 skipping to change at line 1164
char creator[5]; char creator[5];
struct stat statb; struct stat statb;
struct utimbuf times; struct utimbuf times;
int i, r; int i, r;
int main_app; int main_app;
int skip_file; int skip_file;
int cardno, start; int cardno, start;
struct DBInfo info; struct DBInfo info;
char db_copy_name[MAX_DBNAME]; char db_copy_name[MAX_DBNAME];
GList *file_list; GList *file_list;
GList *end_of_list;
int palmos_error; int palmos_error;
int dbIndex; int dbIndex;
pi_buffer_t *buffer; pi_buffer_t *buffer;
#ifdef ENABLE_PLUGINS #ifdef ENABLE_PLUGINS
GList *temp_list; GList *temp_list;
GList *plugin_list; GList *plugin_list;
struct plugin_s *plugin; struct plugin_s *plugin;
#endif #endif
char *file_name; char *file_name;
/* rename_dbnames is used to modify this list to newer databases if needed*/ /* rename_dbnames is used to modify this list to newer databases if needed*/
skipping to change at line 1218 skipping to change at line 1217
{ 0, 0, "u8EZ", NULL}, { 0, 0, "u8EZ", NULL},
{ 0, 0, NULL, NULL} { 0, 0, NULL, NULL}
}; };
unsigned int full_backup; unsigned int full_backup;
jp_logf(JP_LOG_DEBUG, "sync_fetch flags=0x%x, num_backups=%d, fast=%d\n", jp_logf(JP_LOG_DEBUG, "sync_fetch flags=0x%x, num_backups=%d, fast=%d\n",
flags, num_backups, fast_sync); flags, num_backups, fast_sync);
rename_dbnames(palm_dbname); rename_dbnames(palm_dbname);
end_of_list=NULL;
full_backup = flags & SYNC_FULL_BACKUP; full_backup = flags & SYNC_FULL_BACKUP;
/* Fast sync still needs to fetch Saved Preferences before exiting */ /* Fast sync still needs to fetch Saved Preferences before exiting */
if (fast_sync && !full_backup) { if (fast_sync && !full_backup) {
fetch_extra_DBs(sd, extra_dbname); fetch_extra_DBs(sd, extra_dbname);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
if (full_backup) { if (full_backup) {
jp_logf(JP_LOG_DEBUG, "Full Backup\n"); jp_logf(JP_LOG_DEBUG, "Full Backup\n");
pi_watchdog(sd,10); /* prevent Palm timing out on long disk copy times */ pi_watchdog(sd,10); /* prevent Palm timing out on long disk copy times */
sync_rotate_backups(num_backups); sync_rotate_backups(num_backups);
pi_watchdog(sd,0); /* back to normal behavior */ pi_watchdog(sd,0); /* back to normal behavior */
} }
start=cardno=0; start=cardno=0;
file_list=NULL; file_list=NULL;
end_of_list=NULL;
buffer = pi_buffer_new(32 * sizeof(struct DBInfo)); buffer = pi_buffer_new(32 * sizeof(struct DBInfo));
while( (r=dlp_ReadDBList(sd, cardno, dlpDBListRAM | dlpDBListMultiple, start, buffer)) > 0) { while( (r=dlp_ReadDBList(sd, cardno, dlpDBListRAM | dlpDBListMultiple, start, buffer)) > 0) {
for (dbIndex=0; dbIndex < (buffer->used / sizeof(struct DBInfo)); dbIndex+ +) { for (dbIndex=0; dbIndex < (buffer->used / sizeof(struct DBInfo)); dbIndex+ +) {
memcpy(&info, buffer->data + (dbIndex * sizeof(struct DBInfo)), sizeof( struct DBInfo)); memcpy(&info, buffer->data + (dbIndex * sizeof(struct DBInfo)), sizeof( struct DBInfo));
start=info.index+1; start=info.index+1;
creator[0] = (info.creator & 0xFF000000) >> 24; creator[0] = (info.creator & 0xFF000000) >> 24;
creator[1] = (info.creator & 0x00FF0000) >> 16; creator[1] = (info.creator & 0x00FF0000) >> 16;
skipping to change at line 3520 skipping to change at line 3516
* -5 on insufficient VFS space for the file * -5 on insufficient VFS space for the file
* -6 on memory allocation error * -6 on memory allocation error
* >=0 if all went well (size of installed file) * >=0 if all went well (size of installed file)
* *
* Note: Should probably return an ssize_t and refuse to do files > * Note: Should probably return an ssize_t and refuse to do files >
* 2Gb, due to signedness. * 2Gb, due to signedness.
* *
***********************************************************************/ ***********************************************************************/
static int pi_file_install_VFS(const int fd, const char *basename, const int soc ket, const char *vfspath, progress_func f) static int pi_file_install_VFS(const int fd, const char *basename, const int soc ket, const char *vfspath, progress_func f)
{ {
enum { bad_parameters=-1, enum { bad_parameters=-1,
cancel=-2, cancel=-2,
bad_vfs_path=-3, bad_vfs_path=-3,
bad_local_file=-4, bad_local_file=-4,
insufficient_space=-5, insufficient_space=-5,
internal_=-6 internal_=-6
} ; } ;
char rpath[vfsMAXFILENAME]; char rpath[vfsMAXFILENAME];
int rpathlen = vfsMAXFILENAME; int rpathlen = vfsMAXFILENAME;
FileRef file; FileRef file;
unsigned long attributes; unsigned long attributes;
char *filebuffer = NULL; char *filebuffer = NULL;
long volume = -1; long volume = -1;
long used, long used,
total, total,
freespace; freespace;
int int
writesize, writesize,
offset; offset;
size_t readsize; size_t readsize;
size_t written_so_far = 0; size_t written_so_far = 0;
enum { no_path=0, appended_filename=1, retried=2, done=3 } path_steps; enum { no_path=0, appended_filename=1, retried=2, done=3 } path_steps;
struct stat sbuf; struct stat sbuf;
pi_progress_t progress; pi_progress_t progress;
if (fstat(fd,&sbuf) < 0) { if (fstat(fd,&sbuf) < 0) {
fprintf(stderr," ERROR: Cannot stat '%s'.\n",basename); fprintf(stderr," ERROR: Cannot stat '%s'.\n",basename);
return bad_local_file; return bad_local_file;
} }
if (findVFSPath(socket,vfspath,&volume,rpath,&rpathlen) < 0) if (findVFSPath(socket,vfspath,&volume,rpath,&rpathlen) < 0)
{ {
fprintf(stderr,"\n VFS path '%s' does not exist.\n\n", vfspath) fprintf(stderr,"\n VFS path '%s' does not exist.\n\n", vfspath);
; return bad_vfs_path;
return bad_vfs_path; }
}
if (dlp_VFSVolumeSize(socket,volume,&used,&total)<0)
if (dlp_VFSVolumeSize(socket,volume,&used,&total)<0) {
{ fprintf(stderr," Unable to get volume size.\n");
fprintf(stderr," Unable to get volume size.\n"); return bad_vfs_path;
return bad_vfs_path; }
}
/* Calculate free space but leave last 64k free on card */
/* Calculate free space but leave last 64k free on card */ freespace = total - used - 65536 ;
freespace = total - used - 65536 ;
if ((unsigned long)sbuf.st_size > freespace)
if ((unsigned long)sbuf.st_size > freespace) {
{ fprintf(stderr, "\n\n");
fprintf(stderr, "\n\n"); fprintf(stderr, " Insufficient space to install this file on your Palm
fprintf(stderr, " Insufficient space to install this file on yo .\n");
ur Palm.\n"); fprintf(stderr, " We needed %lu and only had %lu available..\n\n",
fprintf(stderr, " We needed %lu and only had %lu available..\n\ (unsigned long)sbuf.st_size, freespace);
n", return insufficient_space;
(unsigned long)sbuf.st_size, freespace); }
return insufficient_space;
}
#define APPEND_BASENAME path_steps-=1; \ #define APPEND_BASENAME path_steps-=1; \
if (rpath[rpathlen-1] != '/') { \ if (rpath[rpathlen-1] != '/') { \
rpath[rpathlen++]='/'; \ rpath[rpathlen++]='/'; \
rpath[rpathlen]=0; \ rpath[rpathlen]=0; \
} \ } \
strncat(rpath,basename,vfsMAXFILENAME-rpathlen-1); \ strncat(rpath,basename,vfsMAXFILENAME-rpathlen-1); \
rpathlen = strlen(rpath); rpathlen = strlen(rpath);
path_steps = no_path; path_steps = no_path;
while (path_steps<retried) while (path_steps<retried)
{ {
/* Don't retry by default. APPEND_BASENAME changes /* Don't retry by default. APPEND_BASENAME changes
the file being tries, so it decrements fd again. the file being tries, so it decrements fd again.
Because we add _two_ here, (two steps fwd, one step back) Because we add _two_ here, (two steps fwd, one step back)
we try at most twice anyway. we try at most twice anyway.
no_path->retried no_path->retried
appended_filename -> done appended_filename -> done
Note that APPEND_BASENAME takes one off, so Note that APPEND_BASENAME takes one off, so
retried->appended_basename retried->appended_basename
*/ */
path_steps+=2; path_steps+=2;
if (dlp_VFSFileOpen(socket,volume,rpath,dlpVFSOpenRead,&file) < 0 if (dlp_VFSFileOpen(socket,volume,rpath,dlpVFSOpenRead,&file) < 0)
) {
{ /* Target doesn't exist. If it ends with a /, try to
/* Target doesn't exist. If it ends with a /, try to create the directory and then act as if the existing
create the directory and then act as if the existing directory was given as target. If it doesn't, carry
directory was given as target. If it doesn't, carry on, it's a regular file to create. */
on, it's a regular file to create. */ if ('/' == rpath[rpathlen-1])
if ('/' == rpath[rpathlen-1]) {
{ /* directory, doesn't exist. Don't try to mkdir /. */
/* directory, doesn't exist. Don't try to mkdir / if ((rpathlen > 1)
. */ && (dlp_VFSDirCreate(socket,volume,rpath) < 0))
if ((rpathlen > 1) {
&& (dlp_VFSDirCreate(socket,volum fprintf(stderr," Could not create destination directory.\n
e,rpath) < 0)) ");
{ return bad_vfs_path;
fprintf(stderr," Could not create desti }
nation directory.\n"); APPEND_BASENAME
return bad_vfs_path; }
} if (dlp_VFSFileCreate(socket,volume,rpath) < 0)
APPEND_BASENAME {
} fprintf(stderr," Cannot create destination file '%s'.\n",
if (dlp_VFSFileCreate(socket,volume,rpath) < 0) rpath);
{ return bad_vfs_path;
fprintf(stderr," Cannot create destination file }
'%s'.\n", }
rpath); else
return bad_vfs_path; {
} /* Exists, and may be a directory, or a filename. If it's
} a filename, that's fine as long as we're installing
else just a single file. */
{ if (dlp_VFSFileGetAttributes(socket,file,&attributes) < 0)
/* Exists, and may be a directory, or a filename. If it's {
a filename, that's fine as long as we're installing fprintf(stderr," Could not get attributes for destination.\n")
just a single file. */ ;
if (dlp_VFSFileGetAttributes(socket,file,&attributes) < 0 (void) dlp_VFSFileClose(socket,file);
) return bad_vfs_path;
{ }
fprintf(stderr," Could not get attributes for d
estination.\n"); if (attributes & vfsFileAttrDirectory)
(void) dlp_VFSFileClose(socket,file); {
return bad_vfs_path; APPEND_BASENAME
} dlp_VFSFileClose(socket,file);
/* Now for sure it's a filename in a directory. */
if (attributes & vfsFileAttrDirectory) } else {
{ dlp_VFSFileClose(socket,file);
APPEND_BASENAME if ('/' == rpath[rpathlen-1])
dlp_VFSFileClose(socket,file); {
/* Now for sure it's a filename in a directory. * /* was expecting a directory */
/ fprintf(stderr," Destination is not a directory.\n");
} else { return bad_vfs_path;
dlp_VFSFileClose(socket,file); }
if ('/' == rpath[rpathlen-1]) }
{ }
/* was expecting a directory */ }
fprintf(stderr," Destination is not a d
irectory.\n");
return bad_vfs_path;
}
}
}
}
#undef APPEND_BASENAME #undef APPEND_BASENAME
if (dlp_VFSFileOpen(socket,volume,rpath,0x7,&file) < 0) if (dlp_VFSFileOpen(socket,volume,rpath,0x7,&file) < 0)
{ {
fprintf(stderr," Cannot open destination file '%s'.\n",rpath); fprintf(stderr," Cannot open destination file '%s'.\n",rpath);
return bad_vfs_path; return bad_vfs_path;
} }
/* If the file already exists we want to truncate it so if we write a sma /* If the file already exists we want to truncate it so if we write a smalle
ller file r file
* the tail of the previous file won't show */ * the tail of the previous file won't show */
if (dlp_VFSFileResize(socket, file, 0) < 0) if (dlp_VFSFileResize(socket, file, 0) < 0)
{ {
fprintf(stderr," Cannot truncate file size to 0 '%s'.\n",rpath) fprintf(stderr," Cannot truncate file size to 0 '%s'.\n",rpath);
; /* Non-fatal error, continue */
/* Non-fatal error, continue */ }
}
#define FBUFSIZ 65536 #define FBUFSIZ 65536
filebuffer = (char *)malloc(FBUFSIZ); filebuffer = (char *)malloc(FBUFSIZ);
if (NULL == filebuffer) if (NULL == filebuffer)
{ {
fprintf(stderr," Cannot allocate memory for file copy.\n"); fprintf(stderr," Cannot allocate memory for file copy.\n");
dlp_VFSFileClose(socket,file); dlp_VFSFileClose(socket,file);
close(fd); close(fd);
return internal_; return internal_;
} }
memset(&progress, 0, sizeof(progress)); memset(&progress, 0, sizeof(progress));
progress.type = PI_PROGRESS_SEND_VFS; progress.type = PI_PROGRESS_SEND_VFS;
progress.data.vfs.path = (char *) basename; progress.data.vfs.path = (char *) basename;
progress.data.vfs.total_bytes = sbuf.st_size; progress.data.vfs.total_bytes = sbuf.st_size;
writesize = 0; writesize = 0;
written_so_far = 0; written_so_far = 0;
while (writesize >= 0) while (writesize >= 0)
{ {
readsize = read(fd,filebuffer,FBUFSIZ); readsize = read(fd,filebuffer,FBUFSIZ);
if (readsize <= 0) break; if (readsize <= 0) break;
offset=0; offset=0;
while (readsize > 0) while (readsize > 0)
{ {
writesize = dlp_VFSFileWrite(socket,file,filebuffer+offse writesize = dlp_VFSFileWrite(socket,file,filebuffer+offset,readsize)
t,readsize); ;
if (writesize < 0) if (writesize < 0)
{ {
fprintf(stderr," Error while writing file.\n"); fprintf(stderr," Error while writing file.\n");
break; break;
} }
readsize -= writesize; readsize -= writesize;
offset += writesize; offset += writesize;
written_so_far += writesize; written_so_far += writesize;
progress.transferred_bytes += writesize; progress.transferred_bytes += writesize;
if ((writesize>0) || (readsize > 0)) { if ((writesize>0) || (readsize > 0)) {
if (f && (f(socket, &progress) == PI_TRANSFER_STO if (f && (f(socket, &progress) == PI_TRANSFER_STOP)) {
P)) { sbuf.st_size = 0;
sbuf.st_size = 0; pi_set_error(socket,PI_ERR_FILE_ABORTED);
pi_set_error(socket,PI_ERR_FILE_ABORTED); goto cleanup;
goto cleanup; }
} }
} }
} }
}
cleanup: cleanup:
free(filebuffer); free(filebuffer);
dlp_VFSFileClose(socket,file); dlp_VFSFileClose(socket,file);
close(fd); close(fd);
return sbuf.st_size; return sbuf.st_size;
} }
/*********************************************************************** /***********************************************************************
* *
* Function: findVFSRoot_clumsy * Function: findVFSRoot_clumsy
* *
* Summary: For internal use only. May contain live weasels. * Summary: For internal use only. May contain live weasels.
* *
* Parameters: root_component --> root path to search for. * Parameters: root_component --> root path to search for.
* match <-> volume matching root_component. * match <-> volume matching root_component.
skipping to change at line 3737 skipping to change at line 3733
* Returns: -2 on VFSVolumeEnumerate error, * Returns: -2 on VFSVolumeEnumerate error,
* -1 if no match was found, * -1 if no match was found,
* 0 if a match was found and @p match is set, * 0 if a match was found and @p match is set,
* 1 if no match but only one VFS volume exists and * 1 if no match but only one VFS volume exists and
* match is set. * match is set.
* *
***********************************************************************/ ***********************************************************************/
static int static int
findVFSRoot_clumsy(int sd, const char *root_component, long *match) findVFSRoot_clumsy(int sd, const char *root_component, long *match)
{ {
int volume_count = 16; int volume_count = 16;
int volumes[16]; int volumes[16];
struct VFSInfo info; struct VFSInfo info;
int i; int i;
int buflen; int buflen;
char buf[vfsMAXFILENAME]; char buf[vfsMAXFILENAME];
long matched_volume = -1; long matched_volume = -1;
if (dlp_VFSVolumeEnumerate(sd,&volume_count,volumes) < 0) if (dlp_VFSVolumeEnumerate(sd,&volume_count,volumes) < 0)
{ {
return -2; return -2;
} }
/* Here we scan the "root directory" of the Pilot. We will fake out /* Here we scan the "root directory" of the Pilot. We will fake out
a bunch of directories pointing to the various "cards" on the a bunch of directories pointing to the various "cards" on the
device. If we're listing, print everything out, otherwise remain device. If we're listing, print everything out, otherwise remain
silent and just set matched_volume if there's a match in the silent and just set matched_volume if there's a match in the
first filename component. */ first filename component. */
for (i = 0; i<volume_count; ++i) for (i = 0; i<volume_count; ++i)
{ {
if (dlp_VFSVolumeInfo(sd,volumes[i],&info) < 0) if (dlp_VFSVolumeInfo(sd,volumes[i],&info) < 0)
continue; continue;
buflen=vfsMAXFILENAME; buflen=vfsMAXFILENAME;
buf[0]=0; buf[0]=0;
(void) dlp_VFSVolumeGetLabel(sd,volumes[i],&buflen,buf); (void) dlp_VFSVolumeGetLabel(sd,volumes[i],&buflen,buf);
/* Not listing, so just check matches and continue. */ /* Not listing, so just check matches and continue. */
if (0 == strcmp(root_component,buf)) { if (0 == strcmp(root_component,buf)) {
matched_volume = volumes[i]; matched_volume = volumes[i];
break; break;
} }
/* volume label no longer important, overwrite */ /* volume label no longer important, overwrite */
sprintf(buf,"card%d",info.slotRefNum); sprintf(buf,"card%d",info.slotRefNum);
if (0 == strcmp(root_component,buf)) { if (0 == strcmp(root_component,buf)) {
matched_volume = volumes[i]; matched_volume = volumes[i];
break; break;
} }
} }
if (matched_volume >= 0) { if (matched_volume >= 0) {
*match = matched_volume; *match = matched_volume;
return 0; return 0;
} }
if ((matched_volume < 0) && (1 == volume_count)) { if ((matched_volume < 0) && (1 == volume_count)) {
/* Assume that with one card, just go look there. */ /* Assume that with one card, just go look there. */
*match = volumes[0]; *match = volumes[0];
return 1; return 1;
} }
return -1; return -1;
} }
/*********************************************************************** /***********************************************************************
* *
* Function: findVFSPath * Function: findVFSPath
* *
* Summary: Search the VFS volumes for @p path. Sets @p volume * Summary: Search the VFS volumes for @p path. Sets @p volume
* equal to the VFS volume matching @p path (if any) and * equal to the VFS volume matching @p path (if any) and
* fills buffer @p rpath with the path to the file relative * fills buffer @p rpath with the path to the file relative
* to the volume. * to the volume.
skipping to change at line 3820 skipping to change at line 3816
* relative path. * relative path.
* *
* Returns: -2 on VFSVolumeEnumerate error, * Returns: -2 on VFSVolumeEnumerate error,
* -1 if no match was found, * -1 if no match was found,
* 0 if a match was found. * 0 if a match was found.
* *
***********************************************************************/ ***********************************************************************/
static int static int
findVFSPath(int sd, const char *path, long *volume, char *rpath, int *rpathlen) findVFSPath(int sd, const char *path, long *volume, char *rpath, int *rpathlen)
{ {
char *s; char *s;
int r; int r;
if ((NULL == path) || (NULL == rpath) || (NULL == rpathlen)) if ((NULL == path) || (NULL == rpath) || (NULL == rpathlen))
return -1; return -1;
if (*rpathlen < strlen(path)) if (*rpathlen < strlen(path))
return -1; return -1;
memset(rpath,0,*rpathlen); memset(rpath,0,*rpathlen);
if ('/'==path[0]) if ('/'==path[0])
strncpy(rpath,path+1,*rpathlen-1); strncpy(rpath,path+1,*rpathlen-1);
else else
strncpy(rpath,path,*rpathlen-1); strncpy(rpath,path,*rpathlen-1);
s = strchr(rpath,'/'); s = strchr(rpath,'/');
if (NULL != s) if (NULL != s)
*s=0; *s=0;
r = findVFSRoot_clumsy(sd, rpath,volume); r = findVFSRoot_clumsy(sd, rpath,volume);
if (r < 0) if (r < 0)
return r; return r;
if (0 == r) if (0 == r)
{ {
/* Path includes card/volume label. */ /* Path includes card/volume label. */
r = strlen(rpath); r = strlen(rpath);
if ('/'==path[0]) if ('/'==path[0])
++r; /* adjust for stripped / */ ++r; /* adjust for stripped / */
memset(rpath,0,*rpathlen); memset(rpath,0,*rpathlen);
strncpy(rpath,path+r,*rpathlen-1); strncpy(rpath,path+r,*rpathlen-1);
} else { } else {
/* Path without card label */ /* Path without card label */
memset(rpath,0,*rpathlen); memset(rpath,0,*rpathlen);
strncpy(rpath,path,*rpathlen-1); strncpy(rpath,path,*rpathlen-1);
} }
if (!rpath[0]) if (!rpath[0])
{ {
rpath[0]='/'; rpath[0]='/';
rpath[1]=0; rpath[1]=0;
} }
*rpathlen = strlen(rpath); *rpathlen = strlen(rpath);
return 0; return 0;
} }
 End of changes. 13 change blocks. 
302 lines changed or deleted 287 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)