ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: Aplonis on September 04, 2013, 09:36:04 AM

Title: "unsafe to write" & "not writeable"
Post by: Aplonis on September 04, 2013, 09:36:04 AM
Trying to write a Perl script to fix date tags for images from camera with clock error. But I'm not understanding something because although the script works, the fixing of tags always fails. Below is the the for-loop, somewhat stripped down, wherein the issue lays. The vars $foo and $bar exactly correspond to the format of the original tags, just with corrected date-time (bunch of Perl time math elsewhere in the script to supply this). What do I miscomprehend so that my script runs without error and yet the writing of tags works not?

for my $file (@files) {
    $exif_tool->ExtractInfo($file, \%options);
    my @tag_list = $exif_tool->GetFoundTags('File');
    for (@tag_list) {
        next unless $_ =~ /Date/;
        if ($_ =~ /Access/) {
            $exif_tool->SetNewValue($_, "$foo");
        } else {
            $exif_tool->SetNewValue($_, "$bar");
        }
    }
}
Title: Re: "unsafe to write" & "not writeable"
Post by: Phil Harvey on September 04, 2013, 09:46:50 AM
Since you're not catching the errors by using SetNewValue in list context, they should go to the console.  You need to add Protected => 1 to the call if you want to write "unsafe" tags.  If you give me more details about a specific tag you are trying to write, and a specific error/warning it gives, I can give you specific more specific.

It seems you may be trying to write FileAccessDate, but this tag is not writable.  See the Extra Tags documentation (https://exiftool.org/TagNames/Extra.html) for more information.

- Phil
Title: Re: "unsafe to write" & "not writeable"
Post by: Aplonis on September 04, 2013, 09:59:29 AM
Yes, the errors go to console. They are as follows...

Sorry, FileCreateDate is unsafe for writing.
Sorry, FileModifyDate is unsafe for writing.
Sorry, FileAccessDate is not writeable.

And having my options now thus...

%options = (PrintConv => 0, Protected => 1);

...with the change of "Protected => 1" being added, makes no difference.

I was trying to make my time-fix script universalish by submitting it to JPG, JP2 & BMP. Results for all three are equivalent.
Title: Re: "unsafe to write" & "not writeable"
Post by: Phil Harvey on September 04, 2013, 10:33:51 AM
The Protected => 1 are extra arguments to the SetNewValue() call, not ExifTool options.  Hopefully this should be clear in the documentation.

- Phil
Title: Re: "unsafe to write" & "not writeable"
Post by: Aplonis on September 04, 2013, 10:44:13 AM
Like so, then....

$exif_tool->SetNewValue($_, $foo, Protected => 1);

...which certainly does away with the errors...

Sorry, FileCreateDate is unsafe for writing.
Sorry, FileModifyDate is unsafe for writing.

...leaving only the error...

Sorry, FileAccessDate is not writeable.

...which is not really at all important.

Thank you. I must have been dense or too hasty in reading the documentation, which I am sure must be fine.