comparison src/filedata.c @ 953:1e61dac76311

Cache strcmp() result.
author zas_
date Mon, 28 Jul 2008 17:59:09 +0000
parents 77a1d5a0326d
children ffbc9195f47f
comparison
equal deleted inserted replaced
952:77a1d5a0326d 953:1e61dac76311
1593 DEBUG_1("Change checked: no write permission: %s", fd->path); 1593 DEBUG_1("Change checked: no write permission: %s", fd->path);
1594 } 1594 }
1595 1595
1596 if (fd->change->dest) 1596 if (fd->change->dest)
1597 { 1597 {
1598 gboolean same;
1598 gchar *dest_dir; 1599 gchar *dest_dir;
1599 const gchar *dest_ext = extension_from_path(fd->change->dest); 1600 const gchar *dest_ext = extension_from_path(fd->change->dest);
1600 if (!dest_ext) dest_ext = ""; 1601 if (!dest_ext) dest_ext = "";
1601 1602
1603 same = (strcmp(fd->path, fd->change->dest) == 0);
1604
1602 if (strcasecmp(fd->extension, dest_ext) != 0) 1605 if (strcasecmp(fd->extension, dest_ext) != 0)
1603 { 1606 {
1604 ret |= CHANGE_WARN_CHANGED_EXT; 1607 ret |= CHANGE_WARN_CHANGED_EXT;
1605 DEBUG_1("Change checked: source and destination have different extensions: %s -> %s", fd->path, fd->change->dest); 1608 DEBUG_1("Change checked: source and destination have different extensions: %s -> %s", fd->path, fd->change->dest);
1606 } 1609 }
1607 1610
1608 if (fd->change->type != FILEDATA_CHANGE_UNSPECIFIED && /* FIXME this is now needed for running editors */ 1611 if (fd->change->type != FILEDATA_CHANGE_UNSPECIFIED && /* FIXME this is now needed for running editors */
1609 strcmp(fd->path, fd->change->dest) == 0) 1612 same)
1610 { 1613 {
1611 ret |= CHANGE_WARN_SAME; 1614 ret |= CHANGE_WARN_SAME;
1612 DEBUG_1("Change checked: source and destination are the same: %s -> %s", fd->path, fd->change->dest); 1615 DEBUG_1("Change checked: source and destination are the same: %s -> %s", fd->path, fd->change->dest);
1613 } 1616 }
1614 1617
1622 else if (!access_file(dest_dir, W_OK)) 1625 else if (!access_file(dest_dir, W_OK))
1623 { 1626 {
1624 ret |= CHANGE_NO_WRITE_PERM_DEST_DIR; 1627 ret |= CHANGE_NO_WRITE_PERM_DEST_DIR;
1625 DEBUG_1("Change checked: destination dir is readonly: %s -> %s", fd->path, fd->change->dest); 1628 DEBUG_1("Change checked: destination dir is readonly: %s -> %s", fd->path, fd->change->dest);
1626 } 1629 }
1627 else if (isfile(fd->change->dest) && (strcmp(fd->change->dest, fd->path) != 0)) 1630 else if (isfile(fd->change->dest) && !same)
1628 { 1631 {
1629 if (!access_file(fd->change->dest, W_OK)) 1632 if (!access_file(fd->change->dest, W_OK))
1630 { 1633 {
1631 ret |= CHANGE_NO_WRITE_PERM_DEST; 1634 ret |= CHANGE_NO_WRITE_PERM_DEST;
1632 DEBUG_1("Change checked: destination file exists and is readonly: %s -> %s", fd->path, fd->change->dest); 1635 DEBUG_1("Change checked: destination file exists and is readonly: %s -> %s", fd->path, fd->change->dest);
1635 { 1638 {
1636 ret |= CHANGE_WARN_DEST_EXISTS; 1639 ret |= CHANGE_WARN_DEST_EXISTS;
1637 DEBUG_1("Change checked: destination exists: %s -> %s", fd->path, fd->change->dest); 1640 DEBUG_1("Change checked: destination exists: %s -> %s", fd->path, fd->change->dest);
1638 } 1641 }
1639 } 1642 }
1640 else if (isdir(fd->change->dest) && (strcmp(fd->change->dest, fd->path) != 0)) 1643 else if (isdir(fd->change->dest) && !same)
1641 { 1644 {
1642 ret |= CHANGE_DEST_EXISTS; 1645 ret |= CHANGE_DEST_EXISTS;
1643 DEBUG_1("Change checked: destination exists: %s -> %s", fd->path, fd->change->dest); 1646 DEBUG_1("Change checked: destination exists: %s -> %s", fd->path, fd->change->dest);
1644 } 1647 }
1645 1648