X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Ffindlib%2Fattribs.c;h=488ed47fdbbef65f7891e8d5dba8dc6fb835a00d;hb=efcbcd6d44bd098025cead6fb990d1f9dfb907fb;hp=c35aaed4c4fd864b3b5005586a352a0d6d76264c;hpb=d426510f6e1cc6d56d6acfd579d5361c5720bdcc;p=bacula%2Fbacula diff --git a/bacula/src/findlib/attribs.c b/bacula/src/findlib/attribs.c index c35aaed4c4..488ed47fdb 100755 --- a/bacula/src/findlib/attribs.c +++ b/bacula/src/findlib/attribs.c @@ -9,7 +9,7 @@ * */ /* - Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker + Copyright (C) 2000-2003 Kern Sibbald and John Walker This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -40,11 +40,15 @@ static int set_win32_attributes(void *jcr, char *fname, char *ofile, char *lname, int type, int stream, struct stat *statp, char *attribsEx, int *ofd); -void unix_name_to_win32(char *name); +void unix_name_to_win32(POOLMEM **win32_name, char *name); extern "C" HANDLE get_osfhandle(int fd); -void win_error(void *jcr, char *prefix, char *ofile); +void win_error(void *jcr, char *prefix, POOLMEM *ofile); #endif +/* For old systems that don't have lchown() use chown() */ +#ifndef HAVE_LCHOWN +#define lchown chown +#endif /*=============================================================*/ /* */ @@ -54,7 +58,7 @@ void win_error(void *jcr, char *prefix, char *ofile); /* Encode a stat structure into a base64 character string */ -void encode_stat(char *buf, struct stat *statp) +void encode_stat(char *buf, struct stat *statp, uint32_t LinkFI) { char *p = buf; /* @@ -89,6 +93,8 @@ void encode_stat(char *buf, struct stat *statp) p += to_base64((int64_t)statp->st_mtime, p); *p++ = ' '; p += to_base64((int64_t)statp->st_ctime, p); + *p++ = ' '; + p += to_base64((int64_t)LinkFI, p); *p = 0; return; } @@ -97,7 +103,7 @@ void encode_stat(char *buf, struct stat *statp) /* Decode a stat packet from base64 characters */ void -decode_stat(char *buf, struct stat *statp) +decode_stat(char *buf, struct stat *statp, uint32_t *LinkFI) { char *p = buf; int64_t val; @@ -140,6 +146,14 @@ decode_stat(char *buf, struct stat *statp) p++; p += from_base64(&val, p); statp->st_ctime = val; + /* Optional FileIndex of hard linked file data */ + if (*p == ' ' || (*p != 0 && *(p+1) == ' ')) { + p++; + p += from_base64(&val, p); + *LinkFI = (uint32_t)val; + } else { + *LinkFI = 0; + } } /* @@ -247,8 +261,7 @@ int encode_attribsEx(void *jcr, char *attribsEx, FF_PKT *ff_pkt) attribsEx[0] = 0; /* no extended attributes */ - pm_strcpy(&ff_pkt->sys_fname, ff_pkt->fname); - unix_name_to_win32(ff_pkt->sys_fname); + unix_name_to_win32(&ff_pkt->sys_fname, ff_pkt->fname); if (!GetFileAttributesEx(ff_pkt->sys_fname, GetFileExInfoStandard, (LPVOID)&atts)) { win_error(jcr, "GetFileAttributesEx:", ff_pkt->sys_fname); @@ -307,6 +320,7 @@ int set_win32_attributes(void *jcr, char *fname, char *ofile, char *lname, WIN32_FILE_ATTRIBUTE_DATA atts; ULARGE_INTEGER li; int fid, stat; + POOLMEM *win32_ofile; if (!p || !*p) { /* we should have attributes */ Dmsg2(100, "Attributes missing. of=%s ofd=%d\n", ofile, *ofd); @@ -345,6 +359,10 @@ int set_win32_attributes(void *jcr, char *fname, char *ofile, char *lname, /* At this point, we have reconstructed the WIN32_FILE_ATTRIBUTE_DATA pkt */ + /* Convert to Windows path format */ + win32_ofile = get_pool_memory(PM_FNAME); + unix_name_to_win32(&win32_ofile, ofile); + if (*ofd == -1) { Dmsg1(100, "File not open: %s\n", ofile); fid = open(ofile, O_RDWR|O_BINARY); /* attempt to open the file */ @@ -360,23 +378,22 @@ int set_win32_attributes(void *jcr, char *fname, char *ofile, char *lname, &atts.ftLastAccessTime, &atts.ftLastWriteTime); if (stat != 1) { - win_error(jcr, "SetFileTime:", ofile); + win_error(jcr, "SetFileTime:", win32_ofile); } close(*ofd); *ofd = -1; } - /* Bash name to Windows format */ - unix_name_to_win32(ofile); Dmsg1(100, "SetFileAtts %s\n", ofile); - stat = SetFileAttributes(ofile, atts.dwFileAttributes & SET_ATTRS); + stat = SetFileAttributes(win32_ofile, atts.dwFileAttributes & SET_ATTRS); if (stat != 1) { - win_error(jcr, "SetFileAttributes:", ofile); + win_error(jcr, "SetFileAttributes:", win32_ofile); } + free_pool_memory(win32_ofile); return 1; } -void win_error(void *vjcr, char *prefix, char *ofile) +void win_error(void *vjcr, char *prefix, POOLMEM *win32_ofile) { JCR *jcr = (JCR *)vjcr; DWORD lerror = GetLastError(); @@ -389,19 +406,19 @@ void win_error(void *vjcr, char *prefix, char *ofile) (LPTSTR)&msg, 0, NULL); - Dmsg3(100, "Error in %s on file %s: ERR=%s\n", prefix, ofile, msg); - Jmsg3(jcr, M_INFO, 0, "Error in %s file %s: ERR=%s\n", prefix, ofile, msg); + Dmsg3(100, "Error in %s on file %s: ERR=%s\n", prefix, win32_ofile, msg); + Jmsg3(jcr, M_INFO, 0, _("Error in %s file %s: ERR=%s\n"), prefix, win32_ofile, msg); LocalFree(msg); } -void unix_name_to_win32(char *name) +/* Cygwin API definition */ +extern "C" void cygwin_conv_to_win32_path(const char *path, char *win32_path); + +void unix_name_to_win32(POOLMEM **win32_name, char *name) { - char *p; - for (p=name; *p; p++) { - if (*p == '/') { - *p = '\\'; - } - } + /* One extra byte should suffice, but we double it */ + *win32_name = check_pool_memory_size(*win32_name, 2*strlen(name)+1); + cygwin_conv_to_win32_path(name, *win32_name); } #endif /* HAVE_CYGWIN */