/* If no writers, close if file or !CAP_ALWAYS_OPEN */
if (dev->num_writers == 0 && (!dev->is_tape() || !dev_cap(dev, CAP_ALWAYSOPEN))) {
+ dvd_remove_empty_part(dcr); /* get rid of any empty spool part */
dev->close();
}
return; /* already closed */
}
- if (is_dvd() && !unmount_dvd(this, 1)) {
- Dmsg1(0, "Cannot unmount device %s.\n", print_name());
- }
-
- /* Remove the last part file if it is empty */
- if (is_dvd() && num_dvd_parts > 0) {
- struct stat statp;
- uint32_t part_save = part;
- POOL_MEM archive_name(PM_FNAME);
- int status;
-
- part = num_dvd_parts;
- make_spooled_dvd_filename(this, archive_name);
- /* Check that the part file is empty */
- status = stat(archive_name.c_str(), &statp);
- if (status == 0 && statp.st_size == 0) {
- Dmsg3(100, "Unlink empty part in close call make_dvd_filename. part=%d num=%d vol=%s\n",
- part, num_dvd_parts, VolCatInfo.VolCatName);
- Dmsg1(100, "unlink(%s)\n", archive_name.c_str());
- unlink(archive_name.c_str());
- if (part_save == part) {
- set_part_spooled(false); /* no spooled part left */
- }
- } else if (status < 0) {
- if (part_save == part) {
- set_part_spooled(false); /* spool doesn't exit */
- }
- }
- part = part_save; /* restore part number */
- }
-
/* Clean up device packet so it can be reused */
clear_opened();
state &= ~(ST_LABEL|ST_READ|ST_APPEND|ST_EOT|ST_WEOT|ST_EOF);
break;
}
if (relabel && dev->is_dvd()) {
- /* Change the partition file name */
- bstrncpy(dcr->VolumeName, newname, sizeof(dcr->VolumeName));
+ /* Save dev VolumeName */
+ bstrncpy(dcr->VolumeName, dev->VolCatInfo.VolCatName, sizeof(dcr->VolumeName));
+ /* Use new name for DVD truncation */
+ bstrncpy(dev->VolCatInfo.VolCatName, newname, sizeof(dev->VolCatInfo.VolCatName));
if (!dev->truncate(dcr)) {
bnet_fsend(dir, _("3912 Failed to truncate previous DVD volume.\n"));
+ /* Restore device VolName */
+ bstrncpy(dev->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dev->VolCatInfo.VolCatName));
break;
}
+ /* Restore device VolName */
+ bstrncpy(dev->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dev->VolCatInfo.VolCatName));
}
free_volume(dev); /* release old volume name */
/* Fall through wanted! */
static void add_file_and_part_name(DEVICE *dev, POOL_MEM &archive_name)
{
char partnumber[20];
+
if (archive_name.c_str()[strlen(archive_name.c_str())-1] != '/') {
pm_strcat(archive_name, "/");
}
return ok;
}
+void dvd_remove_empty_part(DCR *dcr)
+{
+ DEVICE *dev = dcr->dev;
+
+ /* Remove the last part file if it is empty */
+ if (dev->is_dvd() && dev->num_dvd_parts > 0) {
+ struct stat statp;
+ uint32_t part_save = dev->part;
+ POOL_MEM archive_name(PM_FNAME);
+ int status;
+
+ dev->part = dev->num_dvd_parts;
+ make_spooled_dvd_filename(dev, archive_name);
+ /* Check that the part file is empty */
+ status = stat(archive_name.c_str(), &statp);
+ if (status == 0 && statp.st_size == 0) {
+ Dmsg3(100, "Unlink empty part in close call make_dvd_filename. part=%d num=%d vol=%s\n",
+ part_save, dev->num_dvd_parts, dev->VolCatInfo.VolCatName);
+ Dmsg1(100, "unlink(%s)\n", archive_name.c_str());
+ unlink(archive_name.c_str());
+ if (part_save == dev->part) {
+ dev->set_part_spooled(false); /* no spooled part left */
+ }
+ } else if (status < 0) {
+ if (part_save == dev->part) {
+ dev->set_part_spooled(false); /* spool doesn't exit */
+ }
+ }
+ dev->part = part_save; /* restore part number */
+ }
+}
+
bool truncate_dvd(DCR *dcr)
{
DEVICE* dev = dcr->dev;
bool check_can_write_on_non_blank_dvd(DCR *dcr);
int find_num_dvd_parts(DCR *dcr);
off_t lseek_dvd(DCR *dcr, off_t offset, int whence);
+void dvd_remove_empty_part(DCR *dcr);
/* From device.c */
bool open_device(DCR *dcr);
General:
14Sep06
+kes Put removing zero sized spool part file in subroutine and
+ call from release_device().
+kes Add Richard's patch for relabel to dircmd.c, but save and restore
+ dev Volume name.
kes Rework a lot of subroutines in dev.c to take dcr as an
argument. This is done to eliminate the usage of attached_dcrs
in lseek().