File-Temp-0.12 > 0.22 との差分

File::Temp 0.22 と 0.12 の差分

11
22=encoding euc-jp
33
44=head1 NAME
55
66=begin original
77
88File::Temp - return name and handle of a temporary file safely
99
1010=end original
1111
12File::Temp - 一時ファイルの名前とハンドルを安全に返す
12File::Temp - テンポラリファイルの名前とハンドルを安全に返す
1313
1414=begin __INTERNALS
1515
1616=head1 PORTABILITY
1717
1818(ポータビリティ)
1919
2020=begin original
2121
22This section is at the top in order to provide easier access to
22This module is designed to be portable across operating systems
23porters. It is not expected to be rendered by a standard pod
23and it currently supports Unix, VMS, DOS, OS/2 and Windows. When
24formatting tool. Please skip straight to the SYNOPSIS section if you
24porting to a new OS there are generally three main issues
25are not trying to port this module to a new platform.
25that have to be solved:
2626
2727=end original
2828
29この移植者がより簡単にアクセスできるように先頭にあます。
29このモジュールオペレーティングシステムをまたいで移植できるように設計されてお
30これは標準的な pod フォマッツールで表示されることを
30現在、Unix、VMS、DOS、OS/2、Windows をサポートしています。
31想定いません。
31しいOSに移植するときには、一般的に、3つの、解決されなければならない主要な問題がありす:
32あなたがこのモジュールを新しいプラットフォームに
33移植しようとしているのでないなら、SYNOPSIS 節まで読み飛ばしてください。
3432
35=begin original
36
37This module is designed to be portable across operating systems and it
38currently supports Unix, VMS, DOS, OS/2, Windows and Mac OS
39(Classic). When porting to a new OS there are generally three main
40issues that have to be solved:
41
42=end original
43
44このモジュールはオペレーティングシステムをまたいで移植できるように
45設計されており、
46現在、Unix, VMS, DOS, OS/2, Windows, Mac OS (Classic) に対応しています。
47新しい OS に移植するときには、一般的に、三つの解決されなければならない
48主要な問題があります:
49
5033=over 4
5134
5235=item *
5336
5437=begin original
5538
5639Can the OS unlink an open file? If it can not then the
5740C<_can_unlink_opened_file> method should be modified.
5841
5942=end original
6043
61その OS は、開いているファイルを削除できますか?
44そのOSは、開いているファイルを削除できますか?
62もしできなければ、C<_can_unlink_opend_file> メソッドは修正されるべきです。
45もしできなければ、C<_can_unlink_opend_file>メソッドは修正されるべきです。
6346
6447=item *
6548
6649=begin original
6750
6851Are the return values from C<stat> reliable? By default all the
6952return values from C<stat> are compared when unlinking a temporary
7053file using the filename and the handle. Operating systems other than
7154unix do not always have valid entries in all fields. If C<unlink0> fails
7255then the C<stat> comparison should be modified accordingly.
7356
7457=end original
7558
76C<stat> から返される値は信頼出来ますか?
59C<stat>から返される値は信頼出来ますか? デフォルトでは、
77デフォルトでは、C<stat> からの返り値の全てが、ファイル名とハンドルを使う
60C<stat>からの返り値の全てが、ファイル名とハンドルを使う一時ファイルを削除するときに、比較されます。
78一時ファイルを削除するときに比較されます。
7961unix 以外のオペレーティングシステムでは、全てのフィールドについて、
8062妥当な項目があるとは限りません。
81C<unlink0> が失敗すると、C<stat> の比較はそれに合わせて修正されるべきです。
63もし、C<unlink0> が失敗すると、C<stat> の比較はそれに合わせて修正されるべきです。
8264
8365=item *
8466
8567=begin original
8668
8769Security. Systems that can not support a test for the sticky bit
8870on a directory can not use the MEDIUM and HIGH security tests.
8971The C<_can_do_level> method should be modified accordingly.
9072
9173=end original
9274
93セキュリティ。
75セキュリティ。ディレクトリのスティッキービットのテストをサポートしないシステム
94ディレクトリティッキービットのテストをサポートしないシステムは、
76は、中間と、高度、セキュリティテストを使えません。
95MEDIUM と HIGH のセキュリティテストを使えません
77C<_can_do_level>メソッドはそれに応じて、修正されるべきです
96C<_can_do_level> メソッドはそれに応じて修正されるべきです。
9778
9879=back
9980
10081=end __INTERNALS
10182
10283=head1 SYNOPSIS
10384
104 use File::Temp qw/ tempfile tempdir /;
85 use File::Temp qw/ tempfile tempdir /;
10586
106 $fh = tempfile();
87 $dir = tempdir( CLEANUP => 1 );
107 ($fh, $filename) = tempfile();
88 ($fh, $filename) = tempfile( DIR => $dir );
10889
10990 ($fh, $filename) = tempfile( $template, DIR => $dir);
11091 ($fh, $filename) = tempfile( $template, SUFFIX => '.dat');
111 ($fh, $filename) = tempfile( $template, TMPDIR => 1 );
11292
113 binmode( $fh, ":utf8" );
93 $fh = tempfile();
11494
115 $dir = tempdir( CLEANUP => 1 );
116 ($fh, $filename) = tempfile( DIR => $dir );
117
11895=begin original
11996
120Object interface:
121
122=end original
123
124オブジェクトインターフェース:
125
126 require File::Temp;
127 use File::Temp ();
128 use File::Temp qw/ :seekable /;
129
130 $fh = File::Temp->new();
131 $fname = $fh->filename;
132
133 $fh = File::Temp->new(TEMPLATE => $template);
134 $fname = $fh->filename;
135
136 $tmp = File::Temp->new( UNLINK => 0, SUFFIX => '.dat' );
137 print $tmp "Some data\n";
138 print "Filename is $tmp\n";
139 $tmp->seek( 0, SEEK_END );
140
141=begin original
142
143The following interfaces are provided for compatibility with
144existing APIs. They should not be used in new code.
145
146=end original
147
148以下のインターフェースは既存の API との互換性のために提供されています。
149これらは新しいコードでは使うべきではありません。
150
151=begin original
152
15397MkTemp family:
15498
15599=end original
156100
157101MkTemp 系:
158102
159103 use File::Temp qw/ :mktemp /;
160104
161105 ($fh, $file) = mkstemp( "tmpfileXXXXX" );
162106 ($fh, $file) = mkstemps( "tmpfileXXXXXX", $suffix);
163107
164108 $tmpdir = mkdtemp( $template );
165109
166110 $unopened_file = mktemp( $template );
167111
168112=begin original
169113
170114POSIX functions:
171115
172116=end original
173117
174118POSIX 関数:
175119
176120 use File::Temp qw/ :POSIX /;
177121
178122 $file = tmpnam();
179123 $fh = tmpfile();
180124
181125 ($fh, $file) = tmpnam();
126 ($fh, $file) = tmpfile();
182127
183128=begin original
184129
185130Compatibility functions:
186131
187132=end original
188133
189134互換関数:
190135
191136 $unopened_file = File::Temp::tempnam( $dir, $pfx );
192137
138=begin later
139
140Objects (NOT YET IMPLEMENTED):
141
142 require File::Temp;
143
144 $fh = new File::Temp($template);
145 $fname = $fh->filename;
146
147=end later
148
193149=head1 DESCRIPTION
194150
195151=begin original
196152
197C<File::Temp> can be used to create and open temporary files in a safe
153C<File::Temp> can be used to create and open temporary files in a safe way.
198way. There is both a function interface and an object-oriented
154The tempfile() function can be used to return the name and the open
199interface. The File::Temp constructor or the tempfile() function can
155filehandle of a temporary file. The tempdir() function can
200be used to return the name and the open filehandle of a temporary
156be used to create a temporary directory.
201file. The tempdir() function can be used to create a temporary
202directory.
203157
204158=end original
205159
206160C<File::Temp> は、安全な方法で、一時ファイルを作成し、開くのに使えます。
207関数インターェースオブジェクト指向インターフェースの両方がありま
161tempfile() 関数は、一時ァイルの名前、開いたファルハドルを返のに
208File::Temp のコンストラクタと tempfile() 関数は、一時ファイルの名前および
162使われます。
209開いたファイルハンドルを返すのに使われます。
210163tempdir() 関数は、一時ディレクトリを作成するのに使われます。
211164
212165=begin original
213166
214167The security aspect of temporary file creation is emphasized such that
215168a filehandle and filename are returned together. This helps guarantee
216169that a race condition can not occur where the temporary file is
217170created by another process between checking for the existence of the
218171file and its opening. Additional security levels are provided to
219172check, for example, that the sticky bit is set on world writable
220173directories. See L<"safe_level"> for more information.
221174
222175=end original
223176
224177一時ファイルを作成することのセキュリティの側面が、ファイルハンドルと
225178ファイル名が一緒に返されるということで、強調されます。
226179これが、ファイルが存在するかをチェックし、ファイルを開いている間に
227180別のプロセスによってテンポラリファイルが作られる、という
228181競合条件が起こらないことを保証するのを助けています。
229182追加のセキュリティレベルが提供されています;
230183例えば、スティッキービットが全体書き込み可能なディレクトリに
231184セットされているかのチェックです。
232185詳細は L<"safe_level"> を参照してください。
233186
234187=begin original
235188
236189For compatibility with popular C library functions, Perl implementations of
237190the mkstemp() family of functions are provided. These are, mkstemp(),
238191mkstemps(), mkdtemp() and mktemp().
239192
240193=end original
241194
242195一般的な C ライブラリ関数との互換性のために、
243196mkstemp() 関数の仲間の Perl 実装が提供されています。
244197mkstemp(), mkstemps(), mkdtemp(), mktemp() があります。
245198
246199=begin original
247200
248201Additionally, implementations of the standard L<POSIX|POSIX>
249202tmpnam() and tmpfile() functions are provided if required.
250203
251204=end original
252205
253206さらに、もし必要なら、標準の L<POSIX|POSIX> の実装である tmpnam() と
254207tmpfile() が提供されます。
255208
256209=begin original
257210
258211Implementations of mktemp(), tmpnam(), and tempnam() are provided,
259212but should be used with caution since they return only a filename
260213that was valid when function was called, so cannot guarantee
261214that the file will not exist by the time the caller opens the filename.
262215
263216=end original
264217
265218mktemp(), tmpanam(), tempnam() の実装は提供されていますが、
266219注意して使われるべきです;
267220なぜなら、関数が呼ばれると、妥当なファイル名だけを返すので、
268221呼び出し側がファイルを開く時にそのファイルが存在していないことを
269222保証できないからです。
270223
271=begin original
272
273Filehandles returned by these functions support the seekable methods.
274
275=end original
276
277これらの関数で返されるファイルハンドルは seekable メソッドに対応しています。
278
279=cut
280
281=head1 OBJECT-ORIENTED INTERFACE
282
283(オブジェクト指向インターフェース)
284
285=begin original
286
287This is the primary interface for interacting with
288C<File::Temp>. Using the OO interface a temporary file can be created
289when the object is constructed and the file can be removed when the
290object is no longer required.
291
292=end original
293
294これは C<File::Temp> と相互作用するための主インターフェースです。
295OO インターフェースを使うことで、オブジェクトが作成されたときに一時ファイルが
296作成され、オブジェクトが不要になったときにファイルが削除されます。
297
298=begin original
299
300Note that there is no method to obtain the filehandle from the
301C<File::Temp> object. The object itself acts as a filehandle. Also,
302the object is configured such that it stringifies to the name of the
303temporary file, and can be compared to a filename directly. The object
304isa C<IO::Handle> and isa C<IO::Seekable> so all those methods are
305available.
306
307=end original
308
309C<File::Temp> オブジェクトからファイルハンドルを得るメソッドはないことに
310注意してください。
311オブジェクト自身がファイルハンドルとして振る舞います。
312また、オブジェクトは文字列化されると一時ファイル名になるように
313設定されているので、ファイル名と直接比較できます。
314オブジェクトは C<IO::Handle> であり C<IO::Seekable> であるので
315これらの全てのメソッドが利用可能です。
316
317=over 4
318
319=item B<new>
320
321=begin original
322
323Create a temporary file object.
324
325=end original
326
327一時ファイルオブジェクトを作成します。
328
329 my $tmp = File::Temp->new();
330
331=begin original
332
333by default the object is constructed as if C<tempfile>
334was called without options, but with the additional behaviour
335that the temporary file is removed by the object destructor
336if UNLINK is set to true (the default).
337
338=end original
339
340デフォルトではオプションなしで C<tempfile> が呼び出されたかのようにして
341オブジェクトが作成されますが、追加の振る舞いとして、UNLINK が
342真 (これがデフォルトです) の場合、オブジェクトのデストラクタによって
343一時ファイルは削除されます。
344
345=begin original
346
347Supported arguments are the same as for C<tempfile>: UNLINK
348(defaulting to true), DIR, EXLOCK and SUFFIX. Additionally, the filename
349template is specified using the TEMPLATE option. The OPEN option
350is not supported (the file is always opened).
351
352=end original
353
354対応している引数は C<tempfile> と同じです: UNLINK
355(デフォルトは真), DIR, EXLOCK, SUFFIX。
356さらに、ファイル名テンプレートは TEMPLATE オプションを使って指定します。
357OPEN オプションは対応していません (ファイルは常に開かれます)。
358
359 $tmp = File::Temp->new( TEMPLATE => 'tempXXXXX',
360 DIR => 'mydir',
361 SUFFIX => '.dat');
362
363=begin original
364
365Arguments are case insensitive.
366
367=end original
368
369引数は大文字小文字を無視します。
370
371=begin original
372
373Can call croak() if an error occurs.
374
375=end original
376
377エラーが起きると croak() を呼び出すことがあります。
378
379=cut
380
381=item B<newdir>
382
383=begin original
384
385Create a temporary directory using an object oriented interface.
386
387=end original
388
389オブジェクト指向インターフェースを使って一時ディレクトリを作成します。
390
391 $dir = File::Temp->newdir();
392
393=begin original
394
395By default the directory is deleted when the object goes out of scope.
396
397=end original
398
399デフォルトでは、オブジェクトがスコープ外になるとディレクトリは削除されます。
400
401=begin original
402
403Supports the same options as the C<tempdir> function. Note that directories
404created with this method default to CLEANUP => 1.
405
406=end original
407
408C<tempdir> 関数と同じオプションに対応しています。
409このメソッドで作られたディレクトリはデフォルトで CLEANUP => 1 になることに
410注意してください。
411
412 $dir = File::Temp->newdir( $template, %options );
413
414=cut
415
416=item B<filename>
417
418=begin original
419
420Return the name of the temporary file associated with this object
421(if the object was created using the "new" constructor).
422
423=end original
424
425(このオブジェクトが "new" コンストラクタを使って作成されていれば)
426このオブジェクトに関連付けられた一時ファイル名を返します。
427
428 $filename = $tmp->filename;
429
430=begin original
431
432This method is called automatically when the object is used as
433a string.
434
435=end original
436
437このメソッドは、このオブジェクトが文字列として使われると自動的に
438呼び出されます。
439
440=cut
441
442=item B<dirname>
443
444=begin original
445
446Return the name of the temporary directory associated with this
447object (if the object was created using the "newdir" constructor).
448
449=end original
450
451(このオブジェクトが "newdir" コンストラクタを使って作成されていれば)
452このオブジェクトに関連付けられた一時ディレクトリ名を返します。
453
454 $dirname = $tmpdir->dirname;
455
456=begin original
457
458This method is called automatically when the object is used in string context.
459
460=end original
461
462このメソッドは、このオブジェクトが文字列コンテキストで使われると自動的に
463呼び出されます。
464
465=item B<unlink_on_destroy>
466
467=begin original
468
469Control whether the file is unlinked when the object goes out of scope.
470The file is removed if this value is true and $KEEP_ALL is not.
471
472=end original
473
474オブジェクトがスコープ外になったときにファイルを削除(unlink)するかどうかを
475制御します。
476この値が真で、$KEEP_ALL が真でなければ、ファイルは削除されます。
477
478 $fh->unlink_on_destroy( 1 );
479
480=begin original
481
482Default is for the file to be removed.
483
484=end original
485
486デフォルトではファイルは削除されます。
487
488=cut
489
490=item B<DESTROY>
491
492=begin original
493
494When the object goes out of scope, the destructor is called. This
495destructor will attempt to unlink the file (using C<unlink1>)
496if the constructor was called with UNLINK set to 1 (the default state
497if UNLINK is not specified).
498
499=end original
500
501オブジェクトがスコープ外になったとき、デストラクタが呼び出されます。
502このデストラクタは、UNLINK を 1 (UNLINK が指定されなかった場合のデフォルトは
503これです)に設定してコンストラクタが呼び出されていると、(C<unlink1> を使って)
504ファイルを削除しようとします。
505
506=begin original
507
508No error is given if the unlink fails.
509
510=end original
511
512削除に失敗してもエラーは発生しません。
513
514=begin original
515
516If the object has been passed to a child process during a fork, the
517file will be deleted when the object goes out of scope in the parent.
518
519=end original
520
521フォークによってこのオブジェクトが子プロセスに渡されると、
522親でこのオブジェクトがスコープ外になったときにファイルは削除されます。
523
524=begin original
525
526For a temporary directory object the directory will be removed
527unless the CLEANUP argument was used in the constructor (and set to
528false) or C<unlink_on_destroy> was modified after creation.
529
530=end original
531
532一時ディレクトリオブジェクトについては、コンストラクタで
533CLEANUP 引数が使われ(そして偽に設定され)るか、
534作成後に C<unlink_on_destroy> が変更されない限り、
535ディレクトリは削除されます。
536
537=begin original
538
539If the global variable $KEEP_ALL is true, the file or directory
540will not be removed.
541
542=end original
543
544グローバル変数 $KEEP_ALL が真の場合、ファイルやディレクトリは削除されません。
545
546=cut
547
548=back
549
550224=head1 FUNCTIONS
551225
552226(関数)
553227
554228=begin original
555229
556230This section describes the recommended interface for generating
557231temporary files and directories.
558232
559233=end original
560234
561235この節では、一時ファイルと一時ディレクトリを生成するための、
562236推奨されるインターフェースについて説明します。
563237
564238=over 4
565239
566240=item B<tempfile>
567241
568242=begin original
569243
570244This is the basic function to generate temporary files.
571245The behaviour of the file can be changed using various options:
572246
573247=end original
574248
575249これは基本的な関数で、一時ファイルを生成します。
576250ファイルの振る舞いは様々なオプションで変更できます:
577251
578 $fh = tempfile();
579252 ($fh, $filename) = tempfile();
580253
581254=begin original
582255
583256Create a temporary file in the directory specified for temporary
584257files, as specified by the tmpdir() function in L<File::Spec>.
585258
586259=end original
587260
588261L<File::Spec> の tmpdir() 関数で指定される
589262一時ファイル用のディレクトリに、一時ファイルを作成します。
590263
591264 ($fh, $filename) = tempfile($template);
592265
593266=begin original
594267
595268Create a temporary file in the current directory using the supplied
596269template. Trailing `X' characters are replaced with random letters to
597270generate the filename. At least four `X' characters must be present
598at the end of the template.
271in the template.
599272
600273=end original
601274
602275現在のディレクトリに、提供されたテンプレートを使って、
603276一時ファイルを作成します。
604277ファイル名を生成するときに、
605278末尾の文字 `X' はランダムな文字に置き換えられます。
606少なくとも四つの `X' 文字がテンプレートの末尾になければなりません。
279少なくとも四つの `X' 文字がテンプレートになければなりません。
607280
608281 ($fh, $filename) = tempfile($template, SUFFIX => $suffix)
609282
610283=begin original
611284
612285Same as previously, except that a suffix is added to the template
613286after the `X' translation. Useful for ensuring that a temporary
614287filename has a particular extension when needed by other applications.
615288But see the WARNING at the end.
616289
617290=end original
618291
619292`X' の変換の後に接尾辞が加えられることを除いて、前のものと同じです。
620293他のアプリケーションで必要とされるときに、
621294テンポラリファイルに特別の拡張子があるようにしたい場合に便利です。
622295しかし、最後の警告を参照してください。
623296
624297 ($fh, $filename) = tempfile($template, DIR => $dir);
625298
626299=begin original
627300
628301Translates the template as before except that a directory name
629302is specified.
630303
631304=end original
632305
633306ディレクトリの名前が指定されているのを除いて、
634307前述のものと同様にテンプレートを変換します。
635308
636 ($fh, $filename) = tempfile($template, TMPDIR => 1);
637
638=begin original
639
640Equivalent to specifying a DIR of "File::Spec->tmpdir", writing the file
641into the same temporary directory as would be used if no template was
642specified at all.
643
644=end original
645
646DIR に "File::Spec->tmpdir" を指定したのと等価で、
647テンプレートが全く指定されなかった場合に使われる同じ一時ディレクトリに
648ファイルを書き込みます。
649
650309 ($fh, $filename) = tempfile($template, UNLINK => 1);
651310
652311=begin original
653312
654313Return the filename and filehandle as before except that the file is
655automatically removed when the program exits (dependent on
314automatically removed when the program exits. Default is for the file
656$KEEP_ALL). Default is for the file to be removed if a file handle is
315to be removed if a file handle is requested and to be kept if the
657requested and to be kept if the filename is requested. In a scalar
316filename is requested. In a scalar context (where no filename is
658context (where no filename is returned) the file is always deleted
317returned) the file is always deleted either on exit or when it is closed.
659either (depending on the operating system) on exit or when it is
660closed (unless $KEEP_ALL is true when the temp file is created).
661318
662319=end original
663320
664前述のようにファイル名とファイルハンドルを返しますが、($KEEP_ALL に依存して)
321前述のようにファイル名とファイルハンドルを返しますが、
665322プログラムが終了したときに自動的に一時ファイルが削除されます。
666323デフォルトでは、ファイルは、ファイルハンドルが要求されれば削除され、
667324ファイル名が要求されれば保持されます。
668(ファイル名が返されない)スカラコンテキストでは、(オペレーティングシステム
325(ファイル名が返されない)スカラコンテキストでは、終了時か、閉じられたとき
669依存して)終了時か、(一時ファイルが作成されたときに $KEEP_ALL が真でない限り)
326ファイルはいつも削除されます。
670閉じられたときに、ファイルはいつも削除されます。
671327
672328=begin original
673329
674Use the object-oriented interface if fine-grained control of when
675a file is removed is required.
676
677=end original
678
679いつファイルが削除されるかについての細かい制御が必要な場合は、
680オブジェクト指向インターフェースを使ってください。
681
682=begin original
683
684330If the template is not specified, a template is always
685331automatically generated. This temporary file is placed in tmpdir()
686(L<File::Spec>) unless a directory is specified explicitly with the
332(L<File::Spec>) unless a directory is specified explicitly with the
687333DIR option.
688334
689335=end original
690336
691337テンプレートが指定されない場合、テンプレートは常に自動的に生成されます。
692338この一時ファイルは、DIR オプションで明示的にディレクトリが指定されない限り、
693339tmpdir()(L<File::Spec>) に置かれます。
694340
695 $fh = tempfile( DIR => $dir );
341 $fh = tempfile( $template, DIR => $dir );
696342
697343=begin original
698344
699If called in scalar context, only the filehandle is returned and the
345If called in scalar context, only the filehandle is returned
700file will automatically be deleted when closed on operating systems
346and the file will automatically be deleted when closed (see
701that support this (see the description of tmpfile() elsewhere in this
347the description of tmpfile() elsewhere in this document).
702document). This is the preferred mode of operation, as if you only
348This is the preferred mode of operation, as if you only
703have a filehandle, you can never create a race condition by fumbling
349have a filehandle, you can never create a race condition
704with the filename. On systems that can not unlink an open file or can
350by fumbling with the filename. On systems that can not unlink
705not mark a file as temporary when it is opened (for example, Windows
351an open file or can not mark a file as temporary when it is opened
706NT uses the C<O_TEMPORARY> flag) the file is marked for deletion when
352(for example, Windows NT uses the C<O_TEMPORARY> flag))
707the program ends (equivalent to setting UNLINK to 1). The C<UNLINK>
353the file is marked for deletion when the program ends (equivalent
708flag is ignored if present.
354to setting UNLINK to 1). The C<UNLINK> flag is ignored if present.
709355
710356=end original
711357
712358スカラコンテキストで呼ばれると、ファイルハンドルが返され、
713閉じられると、オペレーションシステムが対応していれば(この文書の他の場所に
359閉じられると(この文書の他の場所にある tmpfile() を参照してください)、
714ある tmpfile() を参照してください)、ファイルは自動的に削除されます。
360ファイルは自動的に削除されます。
715361ファイルハンドルだけを持つのなら、これは好ましい方法です;
716362ファイルネームを変更することで競合条件を作ることはありません。
717363開いているファイルを削除できない、あるいはファイルを開いていると
718364一時的であるとしてファイルにマークをつけることのできないシステムでは
719365(たとえば、Windows NT は、C<O_TEMPORARY> フラグを使います)、
720366ファイルは、プログラムの終了時に、削除用のマークがつけられます
721367(UNLINK を 1 に設定するのと同じ)。
722368C<UNLINK> フラグは、あっても無視されます。
723369
724370 (undef, $filename) = tempfile($template, OPEN => 0);
725371
726372=begin original
727373
728374This will return the filename based on the template but
729375will not open this file. Cannot be used in conjunction with
730UNLINK set to true. Default is to always open the file
376UNLINK set to true. Default is to always open the file
731377to protect from possible race conditions. A warning is issued
732378if warnings are turned on. Consider using the tmpnam()
733379and mktemp() functions described elsewhere in this document
734380if opening the file is not required.
735381
736382=end original
737383
738384これはテンプレートを元にしたファイル名を返しますが、そのファイルを
739385開きません。
740386UNILINK を真に設定するのと同時には使えません。
741387デフォルトでは常にファイルを開き、競合条件の可能性から保護します。
742388警告が有効になっている場合は、、警告が出力されます。
743389ファイルを開くことを要求しないなら、この文書の他の場所で説明されている
744390tmpnam() と、mktemp() 関数を使うことを検討してください。
745391
746392=begin original
747393
748If the operating system supports it (for example BSD derived systems), the
749filehandle will be opened with O_EXLOCK (open with exclusive file lock).
750This can sometimes cause problems if the intention is to pass the filename
751to another system that expects to take an exclusive lock itself (such as
752DBD::SQLite) whilst ensuring that the tempfile is not reused. In this
753situation the "EXLOCK" option can be passed to tempfile. By default EXLOCK
754will be true (this retains compatibility with earlier releases).
755
756=end original
757
758(例えば BSD 派生のシステムのように)オペレーティングシステムが
759これに対応しているなら、
760ファイルハンドルは O_EXLOCK (排他ファイルロックで開く) で開かれます。
761これは、目的が、(DBD::SQLite のように) 自分自身で排他ロックを取って
762一時ファイルが再利用されないようにすることを想定している別のシステムに
763パスを渡すことの場合、問題になることがあります。
764この場合、"EXLOCK" オプションを tempfile に渡せます。
765デフォルトでは EXLOCK は真です (これは以前のリリースとの互換性を維持します)。
766
767 ($fh, $filename) = tempfile($template, EXLOCK => 0);
768
769=begin original
770
771394Options can be combined as required.
772395
773396=end original
774397
775オプションは必要に応じて組み合わせることができます。
398オプションは必要に応じて組み合わせることができます。
776399
777=begin original
778
779Will croak() if there is an error.
780
781=end original
782
783エラーがあると croak() します。
784
785=cut
786
787400=item B<tempdir>
788401
789402=begin original
790403
791This is the recommended interface for creation of temporary
404This is the recommended interface for creation of temporary directories.
792directories. By default the directory will not be removed on exit
405The behaviour of the function depends on the arguments:
793(that is, it won't be temporary; this behaviour can not be changed
794because of issues with backwards compatibility). To enable removal
795either use the CLEANUP option which will trigger removal on program
796exit, or consider using the "newdir" method in the object interface which
797will allow the directory to be cleaned up when the object goes out of
798scope.
799406
800407=end original
801408
802409これは、一時ディレクトリを作成するための推奨されるインターフェースです。
803デフォルトで、ディレクトリは終了時削除されせん
410この関数の振舞引数よりす:
804(つまり、これは一時的ではありません; この振る舞いは過去互換性問題により
805変更できません)。
806削除を有効にするには、
807プログラム終了時に削除を行う CLEANUP オプションを使うか、
808オブジェクトインターフェースで "newdir" メソッドを使うことを検討してください;
809これはオブジェクトがスコープ外になったときにディレクトリを
810片付けることができます。
811411
812=begin original
813
814The behaviour of the function depends on the arguments:
815
816=end original
817
818この関数の振る舞いは引数によります:
819
820412 $tempdir = tempdir();
821413
822414=begin original
823415
824416Create a directory in tmpdir() (see L<File::Spec|File::Spec>).
825417
826418=end original
827419
828420tmpdir() でディレクトリを作成します
829421(L<File::Spec|File::Spec> を参照してください)。
830422
831423 $tempdir = tempdir( $template );
832424
833425=begin original
834426
835427Create a directory from the supplied template. This template is
836428similar to that described for tempfile(). `X' characters at the end
837429of the template are replaced with random letters to construct the
838430directory name. At least four `X' characters must be in the template.
839431
840432=end original
841433
842434提供されたテンプレートから、ディレクトリを作成します。
843435このテンプレートは tempfile() で説明されたものと似ています。
844436テンプレートの末尾の `X' 文字はランダムな文字に置き換えられ、
845437ディレクトリ名を作ります。
846438テンプレートには少なくとも四つ `X' 文字がなければいけません。
847439
848440 $tempdir = tempdir ( DIR => $dir );
849441
850442=begin original
851443
852444Specifies the directory to use for the temporary directory.
853445The temporary directory name is derived from an internal template.
854446
855447=end original
856448
857449一時ディレクトリに使うディレクトリを指定します。
858450一時ディレクトリ名は、内部のテンプレートから生成されます。
859451
860452 $tempdir = tempdir ( $template, DIR => $dir );
861453
862454=begin original
863455
864456Prepend the supplied directory name to the template. The template
865457should not include parent directory specifications itself. Any parent
866458directory specifications are removed from the template before
867459prepending the supplied directory.
868460
869461=end original
870462
871463指定されたディレクトリ名をテンプレートに前置します。
872464テンプレートは、親ディレクトリ指定そのものを含むべきではありません。
873465指定されたディレクトリを前置する前に、親ディレクトリ指定は
874466テンプレートから削除されます。
875467
876468 $tempdir = tempdir ( $template, TMPDIR => 1 );
877469
878470=begin original
879471
880Using the supplied template, create the temporary directory in
472Using the supplied template, creat the temporary directory in
881473a standard location for temporary files. Equivalent to doing
882474
883475=end original
884476
885477指定された template を使うと、一時ファイルのための標準の場所に、
886478一時ディレクトリを作ります。
887479次のようにするのと同じですが:
888480
889481 $tempdir = tempdir ( $template, DIR => File::Spec->tmpdir);
890482
891483=begin original
892484
893485but shorter. Parent directory specifications are stripped from the
894486template itself. The C<TMPDIR> option is ignored if C<DIR> is set
895487explicitly. Additionally, C<TMPDIR> is implied if neither a template
896488nor a directory are supplied.
897489
898490=end original
899491
900より短くなります。
492上の方が、短くなります。
901493親ディレクトリ指定はテンプレート自身から除去されます。
902494C<DIR> が明示的に設定されていれば C<TMPDIR> オプションは無視されます。
903495加えて、テンプレートもディレクトリも指定されていなければ、
904496C<TMPDIR> が仮定されます。
905497
906498 $tempdir = tempdir( $template, CLEANUP => 1);
907499
908500=begin original
909501
910Create a temporary directory using the supplied template, but
502Create a temporary directory using the supplied template, but
911503attempt to remove it (and all files inside it) when the program
912504exits. Note that an attempt will be made to remove all files from
913505the directory even if they were not created by this module (otherwise
914506why ask to clean it up?). The directory removal is made with
915507the rmtree() function from the L<File::Path|File::Path> module.
916508Of course, if the template is not specified, the temporary directory
917509will be created in tmpdir() and will also be removed at program exit.
918510
919511=end original
920512
921513一時ディレクトリを提供されたテンプレートを使って作成しますが、
922514プログラムが終了するときに、そのディレクトリ(およびその中の全てのファイル)を
923515削除しようとします。
924516この試みは、このモジュールが作っていないものも含めて、
925517そのディレクトリから全てのファイルを削除しようとします
926518(さもなければなぜ削除するか尋ねますか?)。
927519ディレクトリの除去は L<File::Path|File::Path> の rmtree() 関数で
928520行なわれます。
929521もちろん、テンプレートが指定されていなければ、
930522一時ディレクトリは tempdir() に作られ、プログラムの終了時に削除されます。
931523
932=begin original
933
934Will croak() if there is an error.
935
936=end original
937
938エラーがあると croak() します。
939
940=cut
941
942524=back
943525
944526=head1 MKTEMP FUNCTIONS
945527
946528(MKTEMP 関数)
947529
948530=begin original
949531
950The following functions are Perl implementations of the
532The following functions are Perl implementations of the
951533mktemp() family of temp file generation system calls.
952534
953535=end original
954536
955537以下の関数は、一時ファイルを生成するシステムコールである
956538mktemp() の仲間の Perl の実装です。
957539
958540=over 4
959541
960542=item B<mkstemp>
961543
962544=begin original
963545
964546Given a template, returns a filehandle to the temporary file and the name
965547of the file.
966548
967549=end original
968550
969551テンプレートを与えると、一時ファイルのファイルハンドルとファイル名を返します。
970552
971553 ($fh, $name) = mkstemp( $template );
972554
973555=begin original
974556
975557In scalar context, just the filehandle is returned.
976558
977559=end original
978560
979561スカラコンテキストでは、ファイルハンドルだけが返されます。
980562
981563=begin original
982564
983565The template may be any filename with some number of X's appended
984566to it, for example F</tmp/temp.XXXX>. The trailing X's are replaced
985567with unique alphanumeric combinations.
986568
987569=end original
988570
989571テンプレートは、いくつかの `X' が追加されたファイル名かもしれません;
990572例えば F</tmp/tmp.XXXX>。
991573末尾の X は、ユニークな英数字の組合せに置き換えられます。
992574
993=begin original
994
995Will croak() if there is an error.
996
997=end original
998
999エラーがあると croak() します。
1000
1001=cut
1002
1003575=item B<mkstemps>
1004576
1005577=begin original
1006578
1007579Similar to mkstemp(), except that an extra argument can be supplied
1008580with a suffix to be appended to the template.
1009581
1010582=end original
1011583
584
1012585mkstemp() に似ていますが、特別な引数を与えて、
1013586テンプレートに接尾辞を追加できます。
1014587
1015588 ($fh, $name) = mkstemps( $template, $suffix );
1016589
1017590=begin original
1018591
1019592For example a template of C<testXXXXXX> and suffix of C<.dat>
1020593would generate a file similar to F<testhGji_w.dat>.
1021594
1022595=end original
1023596
1024597例えば、テンプレート が C<testXXXXXX> で接尾辞が C<.dat> なら、
1025598F<testthGji_w.dat> のようなファイルを生成します。
1026599
1027600=begin original
1028601
1029602Returns just the filehandle alone when called in scalar context.
1030603
1031604=end original
1032605
1033606スカラコンテキストで呼ばれると、ただファイル名だけを返します。
1034607
1035=begin original
1036
1037Will croak() if there is an error.
1038
1039=end original
1040
1041エラーがあると croak() します。
1042
1043=cut
1044
1045608=item B<mkdtemp>
1046609
1047610=begin original
1048611
1049612Create a directory from a template. The template must end in
1050613X's that are replaced by the routine.
1051614
1052615=end original
1053616
1054617テンプレートからディレクトリを作成します。
1055618ルーチンによって置き換えられるテンプレートは、
1056619複数の X で終っていなければなりません。
1057620
1058621 $tmpdir_name = mkdtemp($template);
1059622
1060623=begin original
1061624
1062625Returns the name of the temporary directory created.
626Returns undef on failure.
1063627
1064628=end original
1065629
1066630作成された一時ディレクトリの名前を返します。
631失敗すると undef を返します。
1067632
1068633=begin original
1069634
1070635Directory must be removed by the caller.
1071636
1072637=end original
1073638
1074639ディレクトリは、呼び出し元で削除しなければなりません。
1075640
1076=begin original
1077
1078Will croak() if there is an error.
1079
1080=end original
1081
1082エラーがあると croak() します。
1083
1084=cut
1085
1086641=item B<mktemp>
1087642
1088643=begin original
1089644
1090645Returns a valid temporary filename but does not guarantee
1091646that the file will not be opened by someone else.
1092647
1093648=end original
1094649
1095妥当な一時ファイル名を返しますが、そのファイルが他の誰かに
650妥当な一時ファイル名を返します
1096開かれていないことは保証しません。
651ですが、そのファイルが、他の誰かに開かれていないことは保証しません。
1097652
1098653 $unopened_file = mktemp($template);
1099654
1100655=begin original
1101656
1102657Template is the same as that required by mkstemp().
1103658
1104659=end original
1105660
1106661テンプレートは、mkstemp() で必要とされるのと同じです。
1107662
1108=begin original
1109
1110Will croak() if there is an error.
1111
1112=end original
1113
1114エラーがあると croak() します。
1115
1116=cut
1117
1118663=back
1119664
1120665=head1 POSIX FUNCTIONS
1121666
1122667(POSIX 関数)
1123668
1124669=begin original
1125670
1126671This section describes the re-implementation of the tmpnam()
1127and tmpfile() functions described in L<POSIX>
672and tmpfile() functions described in L<POSIX>
1128673using the mkstemp() from this module.
1129674
1130675=end original
1131676
1132677この節は、このモジュールから mkstemp() を使っている、L<POSIX> に
1133678説明されている tmpnam() と tmpfile() 関数の再実装を説明しています。
1134679
1135680=begin original
1136681
1137682Unlike the L<POSIX|POSIX> implementations, the directory used
1138683for the temporary file is not specified in a system include
1139684file (C<P_tmpdir>) but simply depends on the choice of tmpdir()
1140685returned by L<File::Spec|File::Spec>. On some implementations this
1141686location can be set using the C<TMPDIR> environment variable, which
1142687may not be secure.
1143688If this is a problem, simply use mkstemp() and specify a template.
1144689
1145690=end original
1146691
1147692L<POSIX|POSIX> の実装とは違い、一時ファイルに使われるディレクトリは、
1148693システム内部のファイル (C<P_tmpdir>) で指定されているのではなく、
1149694単純に、L<File::Spec|File::Spec> によって、tmpdir() が返すものの選択に
1150695依っています。
1151実装によっては、この場所は、安全ではないかもしれない C<TMPDIR> 環境変数を
696実装によっては、この場所は、C<TMPDIR> 環境変数を使って
1152使って設定されているかもしれません。
697設定されているかもしれません、これは安全ではないかもしれません。
1153698このことが問題なら、単純に、mkstemp() を使い、テンプレートを指定して下さい。
1154699
1155700=over 4
1156701
1157702=item B<tmpnam>
1158703
1159704=begin original
1160705
1161706When called in scalar context, returns the full name (including path)
1162707of a temporary file (uses mktemp()). The only check is that the file does
1163708not already exist, but there is no guarantee that that condition will
1164709continue to apply.
1165710
1166711=end original
1167712
1168713スカラコンテキストで呼ばれたら、(mktemp() を使う)一時ファイルの
1169714(パスを含んだ)フルネームを返します。
1170715ファイルが既に存在しないことだけをチェックしますが、
1171716その状態が適用され続ける保証はありません。
1172717
1173718 $file = tmpnam();
1174719
1175720=begin original
1176721
1177722When called in list context, a filehandle to the open file and
1178723a filename are returned. This is achieved by calling mkstemp()
1179724after constructing a suitable template.
1180725
1181726=end original
1182727
1183728リストコンテキストで呼ばれると、ファイルを開くファイルハンドルと
1184729ファイル名が返ります。
1185730これは、適切なテンプレートを組み立てた後に mkstemp() を呼ぶことで
1186731達成されます。
1187732
1188733 ($fh, $file) = tmpnam();
1189734
1190735=begin original
1191736
1192737If possible, this form should be used to prevent possible
1193738race conditions.
1194739
1195740=end original
1196741
1197742可能なら、潜在的な競合状態を防ぐためにこの形で使うべきです。
1198743
1199744=begin original
1200745
1201746See L<File::Spec/tmpdir> for information on the choice of temporary
1202747directory for a particular operating system.
1203748
1204749=end original
1205750
1206751特定のオペレーティングシステムで
1207752一時ディレクトリを選択するための情報については、
1208753L<File::Spec/tmpdir> を参照してください。
1209754
1210=begin original
1211
1212Will croak() if there is an error.
1213
1214=end original
1215
1216エラーがあると croak() します。
1217
1218=cut
1219
1220755=item B<tmpfile>
1221756
1222757=begin original
1223758
1224Returns the filehandle of a temporary file.
759In scalar context, returns the filehandle of a temporary file.
1225760
1226761=end original
1227762
1228一時ファイルのファイルハンドルを返します。
763スカラコンテキストでは、一時ファイルのファイルハンドルを返します。
1229764
1230765 $fh = tmpfile();
1231766
1232767=begin original
1233768
1234769The file is removed when the filehandle is closed or when the program
1235770exits. No access to the filename is provided.
1236771
1237772=end original
1238773
1239774ファイルハンドルが閉じられるときか、プログラムが終了するときに、
1240775ファイルは削除されます。
1241776ファイル名へのアクセスは提供されていません。
1242777
1243778=begin original
1244779
1245780If the temporary file can not be created undef is returned.
1246781Currently this command will probably not work when the temporary
1247782directory is on an NFS file system.
1248783
1249784=end original
1250785
1251786一時ファイルが作られなければ、undef が返ります。
1252787一時ディレクトリが NFS ファイルシステムの場合、
1253788現在のところこのコマンドはおそらく動きません。
1254789
1255=begin original
1256
1257Will croak() if there is an error.
1258
1259=end original
1260
1261エラーがあると croak() します。
1262
1263=cut
1264
1265790=back
1266791
1267792=head1 ADDITIONAL FUNCTIONS
1268793
1269794(追加の関数)
1270795
1271796=begin original
1272797
1273798These functions are provided for backwards compatibility
1274799with common tempfile generation C library functions.
1275800
1276801=end original
1277802
1278803これらの関数は、共通の一時ファイル生成の C ライブラリ関数の
1279804後方互換のために提供されています。
1280805
1281806=begin original
1282807
1283808They are not exported and must be addressed using the full package
1284name.
809name.
1285810
1286811=end original
1287812
1288813エクスポートされていないので、完全なパッケージ名を使って
1289814記述しなければなりません。
1290815
1291816=over 4
1292817
1293818=item B<tempnam>
1294819
1295820=begin original
1296821
1297822Return the name of a temporary file in the specified directory
1298823using a prefix. The file is guaranteed not to exist at the time
1299the function was called, but such guarantees are good for one
824the function was called, but such guarantees are good for one
1300825clock tick only. Always use the proper form of C<sysopen>
1301826with C<O_CREAT | O_EXCL> if you must open such a filename.
1302827
1303828=end original
1304829
1305830接頭辞を使って指定したディレクトリ内に、一時ファイルのファイル名を返します。
1306831ファイルは関数が呼ばれたそのときに存在していないことを保証されます。
1307832ですが、この保証は一瞬だけのものです。
1308833そのようなファイル名を開かなければならないなら、
1309834C<O_CREAT | O_EXCL> で、C<sysopen> の適切な形を常に使ってください。
1310835
1311836 $filename = File::Temp::tempnam( $dir, $prefix );
1312837
1313838=begin original
1314839
1315840Equivalent to running mktemp() with $dir/$prefixXXXXXXXX
1316(using unix file convention as an example)
841(using unix file convention as an example)
1317842
1318843=end original
1319844
1320845$dir/$prefixXXXXXXXXX で、mktemp() を実行するのと同じです。
1321846(例として、unix のファイルの慣例を使います)
1322847
1323848=begin original
1324849
1325850Because this function uses mktemp(), it can suffer from race conditions.
1326851
1327852=end original
1328853
1329854この関数は mktemp() を使うので、競合状態の影響を受けます。
1330855
1331=begin original
1332
1333Will croak() if there is an error.
1334
1335=end original
1336
1337エラーがあると croak() します。
1338
1339=cut
1340
1341856=back
1342857
1343858=head1 UTILITY FUNCTIONS
1344859
1345860(ユーティリティ関数)
1346861
1347862=begin original
1348863
1349864Useful functions for dealing with the filehandle and filename.
1350865
1351866=end original
1352867
1353868ファイルハンドルとファイル名を扱うための便利関数。
1354869
1355870=over 4
1356871
1357872=item B<unlink0>
1358873
1359874=begin original
1360875
1361876Given an open filehandle and the associated filename, make a safe
1362877unlink. This is achieved by first checking that the filename and
1363878filehandle initially point to the same file and that the number of
1364879links to the file is 1 (all fields returned by stat() are compared).
1365880Then the filename is unlinked and the filehandle checked once again to
1366881verify that the number of links on that file is now 0. This is the
1367882closest you can come to making sure that the filename unlinked was the
1368883same as the file whose descriptor you hold.
1369884
1370885=end original
1371886
1372887開いているファイルハンドルと、関連付けられたファイル名を与えると、
1373888安全に削除します。
1374889これは、ファイル名とファイルハンドルが同じファイルを指し、
1375890ファイルへのリンクの数が、一つであること
1376891(stat()が返す全てのフィールドが比較されます)を
1377892最初にチェックすることで、実現します。
1378893それからファイル名が削除されて、ファイルハンドルが再びチェックされ、
1379894そのファイルのリンクの数が今度は 0 であることを検証します。
1380895このことは、保持しているファイルのディスクリプタと削除されたファイル名が
1381896同じであることを確かめるのに、最も周到です。
1382897
1383 unlink0($fh, $path)
1384 or die "Error unlinking file $path safely";
1385
1386898=begin original
1387899
1388Returns false on error but croaks() if there is a security
1389anomaly. The filehandle is not closed since on some occasions this is
1390not required.
1391
1392=end original
1393
1394エラーのときは偽を返しますが、セキュリティ問題があった場合は croak() します。
1395これが必要でない場合があるので、ファイルハンドルは閉じません。
1396
1397=begin original
1398
1399900On some platforms, for example Windows NT, it is not possible to
1400901unlink an open file (the file must be closed first). On those
1401902platforms, the actual unlinking is deferred until the program ends and
1402903good status is returned. A check is still performed to make sure that
1403904the filehandle and filename are pointing to the same thing (but not at
1404905the time the end block is executed since the deferred removal may not
1405906have access to the filehandle).
1406907
1407908=end original
1408909
1409910プラットフォームによっては(例えば、Windows NT)、開いているファイルを
1410911削除できないものもあります
1411912(ファイルはまず閉じられなければいけません)。
1412913それらのプラットフォームでは、プログラムが終了し、良い状態になるまで、
1413914実際の削除は据え置かれます。
1414915ファイルハンドルとファイル名が同じのを指す事を確かめるまで、チェックは
1415916行なわれます。
1416917(しかし、最後のブロックが実行された時点でなければ、
1417918据え置かれた削除はファイルハンドルにアクセスしないでしょう。)
1418919
1419920=begin original
1420921
1421922Additionally, on Windows NT not all the fields returned by stat() can
1422923be compared. For example, the C<dev> and C<rdev> fields seem to be
1423924different. Also, it seems that the size of the file returned by stat()
1424925does not always agree, with C<stat(FH)> being more accurate than
1425926C<stat(filename)>, presumably because of caching issues even when
1426927using autoflush (this is usually overcome by waiting a while after
1427928writing to the tempfile before attempting to C<unlink0> it).
1428929
1429930=end original
1430931
1431932さらに、Windows NT は、stat() が比較される全てのフィールドを返しません。
1432933例えば、C<dev> と C<rdev> フィールドは異なっているようです。
1433934また、stat() が返すファイルのサイズは、常には一致しません;
1434935C<stat(FH)> は、C<stat(filename)> よりも、狂いがありません;
1435936おそらく、例え自動フラッシュを使っていても、キャッシングの問題によるものです
1436937(これは普通、一時ファイルに書き込んだ後、それを C<unlink0> が試される前に
1437938しばらく待つことで、対処できます)。
1438939
1439940=begin original
1440941
1441942Finally, on NFS file systems the link count of the file handle does
1442943not always go to zero immediately after unlinking. Currently, this
1443944command is expected to fail on NFS disks.
1444945
1445946=end original
1446947
1447最後に、NFS ファイルシステムでは、ファイルハンドルのリンクカウントは、
948最後に、NFS ファイルシステムでは、 ファイルハンドルのリンクカウントは、
1448常に削除の後に 0 になるとは限りません。
949削除の後、すぐは、常には 0 になりません。
1449現在のところ、このコマンドは、NFS ディスク上では失敗すると想定されます。
950現在このコマンドは、NFS ディスク上では失敗すると想定されます。
1450951
1451=begin original
1452
1453This function is disabled if the global variable $KEEP_ALL is true
1454and an unlink on open file is supported. If the unlink is to be deferred
1455to the END block, the file is still registered for removal.
1456
1457=end original
1458
1459グローバル変数 $KEEP_ALL が真で、開いているファイルの
1460削除に対応している場合、この関数は無効になります。
1461削除が END ブロックまで遅延される場合、このファイルは
1462削除のために登録されたままです。
1463
1464=begin original
1465
1466This function should not be called if you are using the object oriented
1467interface since the it will interfere with the object destructor deleting
1468the file.
1469
1470=end original
1471
1472この関数はファイルを削除するオブジェクトデストラクタを妨害するので、
1473オブジェクト指向インターフェースを使っている場合はこの関数は
1474呼び出されるべきではありません。
1475
1476=cut
1477
1478=item B<cmpstat>
1479
1480=begin original
1481
1482Compare C<stat> of filehandle with C<stat> of provided filename. This
1483can be used to check that the filename and filehandle initially point
1484to the same file and that the number of links to the file is 1 (all
1485fields returned by stat() are compared).
1486
1487=end original
1488
1489ファイルハンドルの C<stat> を、指定されたファイル名の C<stat> と比較します。
1490これは、
1491まずファイル名とファイルハンドルが同じファイルを指していて、
1492そのファイルへのリンクの数が 1 であることをチェックするのに使えます。
1493(stat() によって返された全てのフィールドが比較されます)。
1494
1495 cmpstat($fh, $path)
1496 or die "Error comparing handle with file";
1497
1498=begin original
1499
1500Returns false if the stat information differs or if the link count is
1501greater than 1. Calls croak if there is a security anomaly.
1502
1503=end original
1504
1505stat 情報が異なるか、リンクカウントが 1 より大きい場合は、偽を返します。
1506セキュリティ上の異常があると croak を呼び出します。
1507
1508=begin original
1509
1510On certain platforms, for example Windows, not all the fields returned by stat()
1511can be compared. For example, the C<dev> and C<rdev> fields seem to be
1512different in Windows. Also, it seems that the size of the file
1513returned by stat() does not always agree, with C<stat(FH)> being more
1514accurate than C<stat(filename)>, presumably because of caching issues
1515even when using autoflush (this is usually overcome by waiting a while
1516after writing to the tempfile before attempting to C<unlink0> it).
1517
1518=end original
1519
1520例えば Windows のような、一部のプラットフォームでは、
1521stat() によって返された全てのフィールドを比較することはできません。
1522例えば、Windows では C<dev> と C<rdev> フィールドは異なっているように
1523見えます。
1524また、stat() によって返されるファイルサイズは常には一致しません;
1525C<stat(FH)> は C<stat(filename)> より正確になります;
1526おそらく、たとえ autoflush を使ってもキャッシュ問題のためです
1527(これは普通、一時ファイルを書いた後、C<unlink0> を試みる前に、
1528しばらく待つことで克服されます)。
1529
1530=begin original
1531
1532Not exported by default.
1533
1534=end original
1535
1536デフォルトではエクスポートされません。
1537
1538=cut
1539
1540=item B<unlink1>
1541
1542=begin original
1543
1544Similar to C<unlink0> except after file comparison using cmpstat, the
1545filehandle is closed prior to attempting to unlink the file. This
1546allows the file to be removed without using an END block, but does
1547mean that the post-unlink comparison of the filehandle state provided
1548by C<unlink0> is not available.
1549
1550=end original
1551
1552C<unlink0> と同様ですが、cmpstat を使ってファイルを比較した後、
1553ファイルを削除しようとする前にファイルを閉じます。
1554これにより、END ブロックを使わずにファイルを削除できるようになりますが、
1555これは、C<unlink0> によって提供される、ファイルハンドル状態の
1556unlink 後の比較は利用できなくなるということです。
1557
1558 unlink1($fh, $path)
1559 or die "Error closing and unlinking file";
1560
1561=begin original
1562
1563Usually called from the object destructor when using the OO interface.
1564
1565=end original
1566
1567通常は、OO インターフェースを使うときにオブジェクトのデストラクタから
1568呼び出されます。
1569
1570=begin original
1571
1572Not exported by default.
1573
1574=end original
1575
1576デフォルトではエクスポートされません。
1577
1578=begin original
1579
1580This function is disabled if the global variable $KEEP_ALL is true.
1581
1582=end original
1583
1584この関数は、$KEEP_ALL が真の場合は無効になります。
1585
1586=begin original
1587
1588Can call croak() if there is a security anomaly during the stat()
1589comparison.
1590
1591=end original
1592
1593stat() 比較のときにセキュリティの問題がある場合は croak() を
1594呼ぶことがあります。
1595
1596=cut
1597
1598=item B<cleanup>
1599
1600=begin original
1601
1602Calling this function will cause any temp files or temp directories
1603that are registered for removal to be removed. This happens automatically
1604when the process exits but can be triggered manually if the caller is sure
1605that none of the temp files are required. This method can be registered as
1606an Apache callback.
1607
1608=end original
1609
1610この関数を呼び出すと、削除すると登録された全ての一時ファイルや
1611一時ディレクトリが削除されます。
1612これはプロセスの終了時に自動的に行われますが、
1613呼び出し元が一時ファイルを必要としていないことを確実にしたい場合は
1614手動で引き起こすこともできます。
1615このメソッドは Apache のコールバックとして登録できます。
1616
1617=begin original
1618
1619On OSes where temp files are automatically removed when the temp file
1620is closed, calling this function will have no effect other than to remove
1621temporary directories (which may include temporary files).
1622
1623=end original
1624
1625一時ファイルが閉じられたときに一時ファイルが自動的に削除される OS では、
1626この関数を呼び出しても、
1627(一時ファイルが含まれているかもしれない)一時ディレクトリを削除する以外に
1628何の効果もありません。
1629
1630 File::Temp::cleanup();
1631
1632=begin original
1633
1634Not exported by default.
1635
1636=end original
1637
1638デフォルトではエクスポートされません。
1639
1640952=back
1641953
1642954=head1 PACKAGE VARIABLES
1643955
1644956(パッケージ変数)
1645957
1646958=begin original
1647959
1648960These functions control the global state of the package.
1649961
1650962=end original
1651963
1652964これらの関数は、パッケージのグローバルな状態を制御します。
1653965
1654966=over 4
1655967
1656968=item B<safe_level>
1657969
1658970=begin original
1659971
1660972Controls the lengths to which the module will go to check the safety of the
1661973temporary file or directory before proceeding.
1662974Options are:
1663975
1664976=end original
1665977
1666978このモジュールが処理前に一時ファイルか一時ディレクトリを
1667979安全にチェックしようとする程度を制御します。
1668980オプション:
1669981
1670982=over 8
1671983
1672984=item STANDARD
1673985
1674986=begin original
1675987
1676Do the basic security measures to ensure the directory exists and is
988Do the basic security measures to ensure the directory exists and
1677writable, that temporary files are opened only if they do not already
989is writable, that the umask() is fixed before opening of the file,
1678exist, and that possible race conditions are avoided. Finally the
990that temporary files are opened only if they do not already exist, and
1679L<unlink0|"unlink0"> function is used to remove files safely.
991that possible race conditions are avoided. Finally the L<unlink0|"unlink0">
992function is used to remove files safely.
1680993
1681994=end original
1682995
1683996基本的なセキュリティの程度で、以下のことを保証します;
1684997ディレクトリが存在し、書き込み可能であること;
998ファイルを開く前に、umask() が固定されていること;
1685999一時ファイルは、まだ存在していない場合にのみ開いていて、競合条件が
16861000避けられていること。
16871001最後に、ファイルを安全に削除するために
16881002L<unlink0|"unlink0"> 関数が使われます。
16891003
16901004=item MEDIUM
16911005
16921006=begin original
16931007
16941008In addition to the STANDARD security, the output directory is checked
16951009to make sure that it is owned either by root or the user running the
16961010program. If the directory is writable by group or by other, it is then
16971011checked to make sure that the sticky bit is set.
16981012
16991013=end original
17001014
17011015STANDARD の安全性に加えて、出力ディレクトリが root または
17021016プログラムを実行しているユーザのどちらかによって
17031017所有されていることを確かめるチェックをします。
17041018ディレクトリが他のグループかユーザによって書き込み可能であるならば、
17051019スティッキービットがセットされていることを確かめるチェックをします。
17061020
17071021=begin original
17081022
17091023Will not work on platforms that do not support the C<-k> test
17101024for sticky bit.
17111025
17121026=end original
17131027
17141028スティッキービットのための C<-k> テストに対応していないプラットフォームでは
17151029動作しません。
17161030
1031
17171032=item HIGH
17181033
17191034=begin original
17201035
17211036In addition to the MEDIUM security checks, also check for the
17221037possibility of ``chown() giveaway'' using the L<POSIX|POSIX>
17231038sysconf() function. If this is a possibility, each directory in the
1724path is checked in turn for safeness, recursively walking back to the
1039path is checked in turn for safeness, recursively walking back to the
17251040root directory.
17261041
17271042=end original
17281043
17291044MEDIUM の安全性チェックに加えて、L<POSIX|POSIX> sysconf() 関数を使って、
17301045``chown() giveaway'' の可能性もチェックします。
17311046もしこの可能性があれば、それぞれのパスのディレクトリは、
17321047ルートディレクトリまで再帰的に安全性がチェックされます。
17331048
17341049=begin original
17351050
17361051For platforms that do not support the L<POSIX|POSIX>
1737C<_PC_CHOWN_RESTRICTED> symbol (for example, Windows NT) it is
1052C<_PC_CHOWN_RESTRICTED> symbol (for example, Windows NT) it is
17381053assumed that ``chown() giveaway'' is possible and the recursive test
17391054is performed.
17401055
17411056=end original
17421057
17431058L<POSIX|POSIX> の C<_PC_CHOWN_RESTRICTED> シンボルに対応しない
17441059プラットフォーム(たとえば、Windows NT)では、
17451060`chown() giveaway'' が可能であると仮定し、再帰的なテストが行われます。
17461061
17471062=back
17481063
17491064=begin original
17501065
17511066The level can be changed as follows:
17521067
17531068=end original
17541069
17551070レベルは以下のようにして変更できます:
17561071
17571072 File::Temp->safe_level( File::Temp::HIGH );
17581073
17591074=begin original
17601075
17611076The level constants are not exported by the module.
17621077
17631078=end original
17641079
17651080レベル定数はモジュールによってエクスポートされません。
17661081
17671082=begin original
17681083
17691084Currently, you must be running at least perl v5.6.0 in order to
1770run with MEDIUM or HIGH security. This is simply because the
1085run with MEDIUM or HIGH security. This is simply because the
17711086safety tests use functions from L<Fcntl|Fcntl> that are not
17721087available in older versions of perl. The problem is that the version
17731088number for Fcntl is the same in perl 5.6.0 and in 5.005_03 even though
17741089they are different versions.
17751090
17761091=end original
17771092
17781093MEDIUM か HIGH のセキュリティを実行するためには、
17791094今のところ少なくとも Perl v5.6.0 で動かさなければなりません。
17801095これは単純に、安全なテストは v5.6.0 より古いバージョンの perl では
17811096利用できない <Fcntl|Fcntl> から関数を使うからです。
17821097perl 5.6.0 と、5.005_03 の Fcntl のバージョン番号が、それらは
17831098違うものであるにもかかわらず、
17841099バージョン番号が同じであることが問題です。
17851100
17861101=begin original
17871102
17881103On systems that do not support the HIGH or MEDIUM safety levels
17891104(for example Win NT or OS/2) any attempt to change the level will
17901105be ignored. The decision to ignore rather than raise an exception
17911106allows portable programs to be written with high security in mind
17921107for the systems that can support this without those programs failing
17931108on systems where the extra tests are irrelevant.
17941109
17951110=end original
17961111
17971112HIGH と、MEDIUM の安全レベルをサポートしない OS(Win NT や OS/2) では、
17981113レベルを変更しようとしても無視されます。
17991114例外を起こさずに無視すると言う決定により、
18001115移植性のあるプログラムを、
18011116追加のテストが無意味であるシステムでプログラムが失敗するということなしに、
18021117高い安全性に対応することができるシステムのことを考えて、
18031118高いセキュリティで書くことを可能にします。
18041119
18051120=begin original
18061121
18071122If you really need to see whether the change has been accepted
18081123simply examine the return value of C<safe_level>.
18091124
18101125=end original
18111126
18121127もし、実際に変更が受け入れられたかどうかを確認する必要があるなら、
18131128単に C<safe_level> の返り値をを調べてください。
18141129
18151130 $newlevel = File::Temp->safe_level( File::Temp::HIGH );
1816 die "Could not change to high security"
1131 die "Could not change to high security"
18171132 if $newlevel != File::Temp::HIGH;
18181133
1819=cut
1820
18211134=item TopSystemUID
18221135
18231136=begin original
18241137
18251138This is the highest UID on the current system that refers to a root
1826UID. This is used to make sure that the temporary directory is
1139UID. This is used to make sure that the temporary directory is
1827owned by a system UID (C<root>, C<bin>, C<sys> etc) rather than
1140owned by a system UID (C<root>, C<bin>, C<sys> etc) rather than
18281141simply by root.
18291142
18301143=end original
18311144
18321145これは root UID を参照する現在のシステムでもっとも高い UID です。
18331146これは一時ディレクトリが単純に root のものであるのではなくて、
18341147システム UID のもの(C<root>, C<bin>, C<sys> など)であることを確かめるのに、
18351148使われます。
18361149
18371150=begin original
18381151
18391152This is required since on many unix systems C</tmp> is not owned
18401153by root.
18411154
18421155=end original
18431156
18441157多くの unix のシステムで、C</tmp> は root のものではないので、
18451158これが必要とされます。
18461159
18471160=begin original
18481161
18491162Default is to assume that any UID less than or equal to 10 is a root
18501163UID.
18511164
18521165=end original
18531166
18541167デフォルトでは、10 以下のものはどんな UID も root UID と想定します。
18551168
18561169 File::Temp->top_system_uid(10);
18571170 my $topid = File::Temp->top_system_uid;
18581171
18591172=begin original
18601173
18611174This value can be adjusted to reduce security checking if required.
18621175The value is only relevant when C<safe_level> is set to MEDIUM or higher.
18631176
18641177=end original
18651178
18661179必要ならばこの値を調整してセキュリティチェックを下げることもできます。
18671180この値は C<safe_level> がMEDIUM 以上に設定されている場合に関連があります。
18681181
1869=cut
1870
1871=item B<$KEEP_ALL>
1872
1873=begin original
1874
1875Controls whether temporary files and directories should be retained
1876regardless of any instructions in the program to remove them
1877automatically. This is useful for debugging but should not be used in
1878production code.
1879
1880=end original
1881
1882プログラムが一時ファイルやディレクトリを自動的に削除しようとする
1883操作をしても、それらを残したままにするかどうかを制御します。
1884これはデバッグには有用ですが、本番コードで用いるべきではありません。
1885
1886 $File::Temp::KEEP_ALL = 1;
1887
1888=begin original
1889
1890Default is for files to be removed as requested by the caller.
1891
1892=end original
1893
1894デフォルトは、呼び出し元によって要求された場合にファイルを削除します。
1895
1896=begin original
1897
1898In some cases, files will only be retained if this variable is true
1899when the file is created. This means that you can not create a temporary
1900file, set this variable and expect the temp file to still be around
1901when the program exits.
1902
1903=end original
1904
1905場合によっては、ファイルが作られた時点でこの変数が真の場合にのみ
1906ファイルが残されます。
1907つまり、一時ファイルを作って、この変数を設定しても、
1908プログラムが終了したときにこの一時ファイルがまだ残っていることを
1909想定できないということです。
1910
1911=item B<$DEBUG>
1912
1913=begin original
1914
1915Controls whether debugging messages should be enabled.
1916
1917=end original
1918
1919デバッグメッセージを有効にするかどうかを制御します。
1920
1921 $File::Temp::DEBUG = 1;
1922
1923=begin original
1924
1925Default is for debugging mode to be disabled.
1926
1927=end original
1928
1929デフォルトは、デバッグモードを無効にします。
1930
19311182=back
19321183
19331184=head1 WARNING
19341185
19351186(警告)
19361187
19371188=begin original
19381189
19391190For maximum security, endeavour always to avoid ever looking at,
19401191touching, or even imputing the existence of the filename. You do not
19411192know that that filename is connected to the same file as the handle
19421193you have, and attempts to check this can only trigger more race
19431194conditions. It's far more secure to use the filehandle alone and
19441195dispense with the filename altogether.
19451196
19461197=end original
19471198
19481199最高のセキュリティのためには、あるファイルの存在を、調べたり、
19491200作成したり、仮定したりすることを避けるように努力して下さい。
19501201そのファイル名があなたの持っているハンドルと同じファイルに
19511202接続されているかどうかはわかりませんし、
19521203それを調べようとすることはより多くの競合状態を引き起こすだけです。
19531204ファイルハンドルだけを使い、ファイル名と切り離す方があるかに安全です。
19541205
19551206=begin original
19561207
19571208If you need to pass the handle to something that expects a filename
19581209then, on a unix system, use C<"/dev/fd/" . fileno($fh)> for arbitrary
19591210programs, or more generally C<< "+<=&" . fileno($fh) >> for Perl
19601211programs. You will have to clear the close-on-exec bit on that file
19611212descriptor before passing it to another process.
19621213
19631214=end original
19641215
19651216ファイルネームを期待するものにハンドルを渡す必要があるなら、
19661217unix システムでは、任意のプログラムに対して C<"/dev/fd/" . fileno($fh)> を
19671218使ってください;
19681219または、より一般的に Perl のプログラムのために
19691220C<< "+<=&" . fileno($fh) >> を使って下さい。
19701221他のプロセスにそれを渡す前にファイル記述子で close-on-exec ビット
19711222をクリアする必要があるでそしょう。
19721223
19731224 use Fcntl qw/F_SETFD F_GETFD/;
19741225 fcntl($tmpfh, F_SETFD, 0)
19751226 or die "Can't clear close-on-exec flag on temp fh: $!\n";
19761227
19771228=head2 Temporary files and NFS
19781229
1979(一時ファイルと NFS)
1230(一時ファイルとNFS)
19801231
19811232=begin original
19821233
19831234Some problems are associated with using temporary files that reside
19841235on NFS file systems and it is recommended that a local filesystem
19851236is used whenever possible. Some of the security tests will most probably
19861237fail when the temp file is not local. Additionally, be aware that
19871238the performance of I/O operations over NFS will not be as good as for
19881239a local disk.
19891240
19901241=end original
19911242
19921243NFS ファイルシステムにある一時ファイルを使うことに関してはいくつかの
19931244問題があり、出来る限りローカルのファイルシステムを使うことが
19941245推奨されます。
19951246いくつかのセキュリティテストは、一時ファイルがローカルにない場合、
19961247ほとんどたいてい失敗するでしょう。
19971248更に、NFS 越しの I/O 操作はローカルディスクほど良くないことに
19981249気をつけて下さい。
19991250
2000=head2 Forking
2001
2002(fork する)
2003
2004=begin original
2005
2006In some cases files created by File::Temp are removed from within an
2007END block. Since END blocks are triggered when a child process exits
2008(unless C<POSIX::_exit()> is used by the child) File::Temp takes care
2009to only remove those temp files created by a particular process ID. This
2010means that a child will not attempt to remove temp files created by the
2011parent process.
2012
2013=end original
2014
2015場合によっては File::Temp によって作られたファイルは END ブロックの中で
2016削除されます。
2017(C<POSIX::_exit()> が子で使われていない限り) 子プロセスの終了時に
2018END ブロックが実行されるので、
2019File::Temp は特定のプロセス ID で作成された一時ファイルのみを削除するように
2020注意を払います。
2021つまり、子プロセスは親プロセスによって作られた一時ファイルを
2022削除しようとしません。
2023
2024=begin original
2025
2026If you are forking many processes in parallel that are all creating
2027temporary files, you may need to reset the random number seed using
2028srand(EXPR) in each child else all the children will attempt to walk
2029through the same set of random file names and may well cause
2030themselves to give up if they exceed the number of retry attempts.
2031
2032=end original
2033
2034もしそれぞれが一時ファイルを作る多くのプロセスを平行に fork するなら、
2035それぞれの子で srand(EXPR) を使うことで乱数の種をリセットする必要が
2036あるかもしれません; さもなければ全ての子が同じランダムファイル名の
2037集合を通過しようとして、再試行回数を超えると諦めてしまうかもしれません。
2038
2039=head2 Directory removal
2040
2041(ディレクトリの削除)
2042
2043=begin original
2044
2045Note that if you have chdir'ed into the temporary directory and it is
2046subsequently cleaned up (either in the END block or as part of object
2047destruction), then you will get a warning from File::Path::rmtree().
2048
2049=end original
2050
2051一時ディレクトリに chdir して、その後(END ブロックやオブジェクト破壊の
2052一部として)それを片付けると、
2053File::Path::rmtree() から警告が出ることに注意してください。
2054
2055=head2 BINMODE
2056
2057=begin original
2058
2059The file returned by File::Temp will have been opened in binary mode
2060if such a mode is available. If that is not correct, use the C<binmode()>
2061function to change the mode of the filehandle.
2062
2063=end original
2064
2065File::Temp から返されたファイルは、(モードがある場合は)バイナリモードで
2066開かれます。
2067これが正しくない場合、ファイルハンドルのモードを変更するために
2068C<binmode()> 関数を使ってください。
2069
2070=begin original
2071
2072Note that you can modify the encoding of a file opened by File::Temp
2073also by using C<binmode()>.
2074
2075=end original
2076
2077C<binmode()> を使うことで、File::Temp によって開かれたファイルの
2078エンコーディングを変更できることに注意してください。
2079
20801251=head1 HISTORY
20811252
2082(歴史)
1253(経緯)
20831254
20841255=begin original
20851256
20861257Originally began life in May 1999 as an XS interface to the system
20871258mkstemp() function. In March 2000, the OpenBSD mkstemp() code was
20881259translated to Perl for total control of the code's
20891260security checking, to ensure the presence of the function regardless of
2090operating system and to help with portability. The module was shipped
1261operating system and to help with portability.
2091as a standard part of perl from v5.6.1.
20921262
20931263=end original
20941264
20951265もともとは、1999 年の 5 月にシステムの mkstemp() 関数への
20961266XS インターフェースとして生まれました。
209712672000 年 5 月に、コードのセキュリティチェックを完全に制御するために、
20981268OpenBSD の mkstemp() コードが Perl に移植されました;
20991269オペレーティングシステムに依存しない関数の存在を保証することになり、
21001270移植性を助けることになりました。
2101このモジュールは v5.6.1 から perl の標準として配布されています。
21021271
21031272=head1 SEE ALSO
21041273
21051274L<POSIX/tmpnam>, L<POSIX/tmpfile>, L<File::Spec>, L<File::Path>
21061275
21071276=begin original
21081277
2109See L<IO::File> and L<File::MkTemp>, L<Apache::TempFile> for
1278See L<IO::File> and L<File::MkTemp> for different implementations of
2110different implementations of temporary file handling.
1279temporary file handling.
21111280
21121281=end original
21131282
2114一時ファイルを扱う異なった実装については L<IO::File>, L<File::MkTemp>,
1283一時ファイルを扱う異なった実装については L<IO::File> L<File::MkTemp>
2115L<Apache::TempFile> を参照してください。
1284参照してください。
21161285
2117=begin original
2118
2119See L<File::Tempdir> for an alternative object-oriented wrapper for
2120the C<tempdir> function.
2121
2122=end original
2123
2124もう一つの C<tempdir> 関数のオブジェクト指向のラッパーについては
2125L<File::Tempdir> を参照してください。
2126
21271286=head1 AUTHOR
21281287
2129Tim Jenness E<lt>tjenness@cpan.orgE<gt>
1288Tim Jenness E<lt>t.jenness@jach.hawaii.eduE<gt>
21301289
2131Copyright (C) 2007-2009 Tim Jenness.
1290Copyright (C) 1999-2001 Tim Jenness and the UK Particle Physics and
2132Copyright (C) 1999-2007 Tim Jenness and the UK Particle Physics and
21331291Astronomy Research Council. All Rights Reserved. This program is free
21341292software; you can redistribute it and/or modify it under the same
21351293terms as Perl itself.
21361294
2137Original Perl implementation loosely based on the OpenBSD C code for
1295Original Perl implementation loosely based on the OpenBSD C code for
21381296mkstemp(). Thanks to Tom Christiansen for suggesting that this module
21391297should be written and providing ideas for code improvements and
21401298security enhancements.
2141
2142=cut
21431299
21441300=begin meta
21451301
21461302Update: SHIRAKATA Kentaro <argrath@ub32.org> (0.12-)
21471303Status: completed
21481304
21491305=end meta